Python 已经安装了 python 的 jenkins 但是在 pycharm 中无法使用,报 AttributeError: module 'jenkins' has no attribute 'Jenkins'

咸吃萝卜淡操心 · 2019年02月27日 · 最后由 咸吃萝卜淡操心 回复于 2019年02月27日 · 3342 次阅读

使用 pip3 install python-jenkins 后在 pycharm 中使用,运行以后报错,但是在命令行使用就没问题,已经确认 pycharm 环境中有 python-jenkins

import jenkins
jenkins_server_url='http://localhost:8080'
user_id='admin'
api_token='admin'
server = jenkins.Jenkins('http://localhost:8080', username=user_id, password=api_token)

Traceback (most recent call last):
  File "/Users/xxxx/PycharmProjects/untitled/jenkins.py", line 3, in <module>
    import jenkins
  File "/Users/xxxx/PycharmProjects/untitled/jenkins.py", line 16, in <module>
    server = jenkins.Jenkins('http://localhost:8080', username=user_id, password=api_token)
AttributeError: module 'jenkins' has no attribute 'Jenkins'

共收到 3 条回复 时间 点赞

你的文件名不应该和模块名重复,否则导入的时候会找不到

jenkins.py 这个文件不要和已存在的模块 jenkins 重名

楼上正解,模块名不能和文件名重名,否则会报错。

Jerry li 回复

谢谢解答,一直没注意过这方面的东西,又学到了

咸吃萝卜淡操心 关闭了讨论 02月27日 13:17
需要 登录 後方可回應,如果你還沒有帳號按這裡 注册