简体   繁体   English

python:无法导入名称JIRA

[英]python : cannot import name JIRA

I have already done pip install jira 我已经完成了pip install jira

but when I run the following it fails with ImportError: cannot import name JIRA 但是当我运行以下命令时,它会导致ImportError失败: 无法导入名称JIRA

import re
from jira import JIRA

jira = JIRA('https://issues.net')
# all values are samples and won't work in your code!
key_cert_data = None
key_cert_file = "cert/jiraprivatekey.pub"
with open(key_cert, 'r') as key_cert_file:
    key_cert_data = key_cert_file.read()

fixed it. 修复。

The file I was running was called jira.py so when I did from 我运行的文件名为jira.py,所以当我做的时候

jira import JIRA jira导入JIRA

It was trying to look up self. 它试图抬头看自己。

In addition to @Organ note 除了@Organ注意

I'd like to note that you can turn on absolute import paths and keep your file named jira.py if it makes sense to you to do that 我想请注意,您可以启用绝对导入路径,并将文件命名为jira.py,如果它对您有意义的话

In my case, I did this twice: 就我而言,我做了两次:

from jira import JIRA
jira = JIRA(URL_JIRA, basic_auth=('abc', '123'))

So in the first show, it's working good because jira is the global namespace but in second usage it doesn't because jira became just instance of JIRA. 因此在第一个节目中,它的工作正常,因为jira是全局命名空间,但在第二次使用中它并不是因为jira只是JIRA的实例。

This is my solution based on Organ's note: 这是我基于Organ的说明的解决方案:

import jira.client
x = jira.client.JIRA(URL_JIRA, basic_auth=('123', 'abc'))

Here, you can keep having jira.py and use these lines as much as you need. 在这里,您可以继续使用jira.py并根据需要使用这些行。

I started getting this error when I installed python 3.6,earlier I had python 2.7. 当我安装python 3.6时,我开始收到此错误,之前我有python 2.7。 and jira was working. 和吉拉正在工作。 I renamed the python3.6 exe as python3 and python 2.7 exe as python, issue got resolved 我将python3.6 exe重命名为python3,将python 2.7 exe重命名为python,问题得到解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM