"No module named xx" when editing file, but python executes it fine


(Apologies in advance that I am pretty new to Python and Pycharm..)

We have a Python library package stored in our git repository.  This has a setup.py file using setuptools and creates an egg when run.

In another application, we have another setup.py file which lists the library in the install_requires section.  It also lists it in dependency_links.  So it looks a bit like:

install_requires= [ 'my_library == 1.0.0' ],

dependency_links = [ 



After installing (python setup.py install from terminal within the virtual env.),, I can see in my venv site-packages that there is a "my_library-1.0.0-py3.5.egg.  Opening this up I can see the files pulled down from git and all seems fine.

When I run my application, imports such as "import my_module" that come from this dependency work fine.  However, PyCharm put red wiggly underlines and says "No module named my_module".

(By "run" I mean from the terminal or right clicking and running from Pycharm)

I'm using a virtualenv (which I created through pycharm), Python version 3.5.2 on Ubuntu.  I can see this set up as the interpreter in project settings.

Any idea how I can make this work?  


Can you successfully run your code that has "import my_module" inside PyCharm using the "Run" action from the context menu of a file with this import?

Please check that your sys.path and your File | Settings | Project | Project Interpreter | More | Show Paths are the same.


Slightly embarrassing but I quit PyCharm and restarted and now it seems OK.  I wonder if PyCharm (and then me!) got confused because I'd been working on a related problem which I resolved, but then PyCharm stayed "broken".  Although I had tried turning it off and on again, I obviously didn't once I got the other problem resolved!

Whilst it was broken, right clicking and running the file worked fine.

I never knew you could list the paths like that from Pycharm.  If it happens again that's the first place I will look.

Thanks very much for the quick and helpful reply - apologies that it turned out to be a silly thing, but you've still given me something useful all the same.


I have a very similar problem, and haven't been able to solve it after trying a number of ways.

Situation: I am using Windows 10, and both Python 2.7 and Python 3.6 are installed; the folders for the former is before the latter in the PATH variable. The project is configured to use Python 3.6 (using the system installation or a local virtual environment has the same outcome). PyCharm says: "No module named math". Needless to say, the module is available and the script works. 

What hasn't worked: As hinted above, I deleted the interpreter settings, then re-configured it, either to the system installation or to use a virtual environment. I deleted the cache and restarted it. I checked if PYTHON_PATH is set (it is not). 

This problem seems to be prevalent among PyCharm users. PyCharm is a great environment, but it would be sooo good if you could solve this issue as well.



The same problem after last pyCharm update (2017.3).

It seems like no math module installed, but if I run the same file (right click, run) - there's no problem.


I updated to PyCharm 2017.3.1 today and I'm seeing this same issue with `math` module. Doing "Invalidate caches and restart" doesn't help. Nor does deleting the interpreter definition and re-adding it.  The interpreter I'm currently using is Python 3.6.2 for Windows 64 bit.


I am using PyCharm 2017.3.1 as well.  I am on Mac OS X El Capitan (10.11.6), running Python 2.7.10 with a virtualenv interpreter.  Using a long-existing PyCharm project, the following standard modules trigger the "No module named {module}" IDE error:  time, operator, math

I created a brand new virtualenv along with a new PyCharm project, and made it available to all projects.  The above mentioned errors went away.  I then deleted both the project and the virtualenv, finally restarting PyCharm.  The errors did not reappear.

Seems like a weird way to fix this issue, but this procedure worked for me.


None of these workarounds are working for me. I've tried several new Java projects (adding the Python interpreter) different virtualenvs and even python on outside a virtualenv and nothing works. I'm running on a mac with High Sierra with IntelliJ 2017.3.2.


I had a similar issue with IntelliJ IDEA Ultimate 2018.2. My simple Python script starts with import sys and IDEA was flagging sys with "No module named sys". After invalidating the caches and restarting, the issue went away. Of course, YMMV.


I faced this problem recently. Some old settings left after i reinstalled Windows.

I used following steps to solve the problem:

1) recreate project 

2) reconfigure python plugin


I'm facing the same issue with IntelliJ Ultimate Edition.


>I'm facing the same issue with IntelliJ Ultimate Edition.

Have you tried "File >> Invatidate caches / restart" and recreating python interpreter?


Thanks for looking into it. I think I face the issue as soon as I add __init__.py file to any package. Once I delete the file, the errors go away.


Please sign in to leave a comment.