python : cannot import name JIRA
Asked Answered
A

4

12

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()
Algometer answered 12/1, 2017 at 19:38 Comment(2)
Possible duplicate of ImportError: Cannot import name XBackside
Possible duplicate of Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"Lovieloving
A
35

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.

Algometer answered 12/1, 2017 at 20:0 Comment(3)
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 thatCrossroad
@std''OrgnlDave Can you explain how?Oliveolivegreen
@Oliveolivegreen added an answer explaining howScathe
S
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.

Scathe answered 13/4, 2018 at 13:59 Comment(0)
A
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

Aylsworth answered 10/11, 2018 at 15:8 Comment(0)
D
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.

Dragging answered 26/8, 2023 at 4:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.