pcauthorn
pcauthorn

Reputation: 390

Import issue with Pycharm

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?

Upvotes: 2

Views: 161

Answers (2)

Buzz
Buzz

Reputation: 1412

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

Upvotes: 2

anarchy
anarchy

Reputation: 5184

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

Upvotes: 0

Related Questions