Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading