11

I have already done pip install jira

but when I run the following it fails with ImportError: cannot import name 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()
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Scooby
  • 3,371
  • 8
  • 44
  • 84
  • Possible duplicate of [ImportError: Cannot import name X](http://stackoverflow.com/questions/9252543/importerror-cannot-import-name-x) – nbrooks Jan 12 '17 at 20:02
  • Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – pppery Aug 20 '19 at 15:24

4 Answers4

33

fixed it.

The file I was running was called jira.py so when I did from

jira import JIRA

It was trying to look up self.

Scooby
  • 3,371
  • 8
  • 44
  • 84
0

In addition to @Organ note

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

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.

This is my solution based on Organ's note:

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.

HMagdy
  • 3,029
  • 33
  • 54
0

I started getting this error when I installed python 3.6,earlier I had 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

sgupt
  • 1
0

In my case from jira import Jira was resolved with next steps:

  1. run in command line under (venv) :
pip install jira 
pip install 'jira[cli]'

or if you are not in (venv):

pip install jira 
python -m venv jira_python
source jira_python/bin/activate
pip install 'jira[cli]'
  1. Add into block of imports of your *.py file:
from jira import JIRA
jira = JIRA('https://jira.atlassian.com')

The official doc you will find here:
https://jira.readthedocs.io/installation.html
and here:
https://pypi.org/project/jira/

Hope somebody it will helps.