2

I am writing a module in Python called silk.jira.create.create

In that module I'm trying to import the jira third party module that I installed with pip.

from jira import JIRA

When I run the module I see a Error:

ImportError: cannot import name 'JIRA' from 'jira'

looking in the debug console I can see PyCharm is confused and has imported the wrong module. ie


jira.__file__
'C:\\<full path>\\silk\\jira\\__init__.py' <- I'm expecting the third party here

If I run this outside of PyCharm with python -m it works (no ImportError).

Any ideas what's going on here?

1
  • you might have a different python / conda environment running in pycharm. have you checked that you are using the right one? Commented Oct 11, 2022 at 20:43

2 Answers 2

2

PyCharm includes your working directories, including your module folder if you labeled it as source dir, into PYTHONPATH. By doing so you got two modules named jira in your environment.

You should either rename your module (highly advisable in general to avoid confusion and interference!) or remove the specific path from the python interpreter that you set on PyCharm. To do so, go to Python Interpreter (bottom right on status bar), then Show All and click on the directory trees.

By doing so, you might not be able to see your module at all when importing. You have to use import declaration relative to your project root directory

Sign up to request clarification or add additional context in comments.

3 Comments

Not exactly sure why it's getting confused with silk.jira but I see your point. I'll just rename it. Thanks
Much really depends on how you set your workspace. Lacking extra info on it, it's difficult to point exactly what's confusing PyCharm.
PyCharm does some extra configuration that make great this IDE, but at the same time one can have hard time understanding what it is doing under the hood.
0

I can see that you are using windows.

Pycharm doesn't have python inside, it uses the python installed in your system. You can have multiple installation of python in the same system.

Firstly, check where you have installed python and if you have multiple installations.

You could have it installed using the microsoft store, from the python3 website or from a packages manager like anaconda or miniconda.

Then select the correct interpreter using this pycharm guide after you figure it out.

https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html

1 Comment

Interesting idea that I double checked on your suggestion. I was using a venv and could see that it was the same interpreter. It looks like PyCharm adds the same director that a script lives to the PYTHON_PATH. This makes it easy to run modules anywhere but can cause some weird behavior like this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.