Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm does not recognize modules installed in development mode

I have two pure python projects in PyCharm 3.4.1 Professional Edition. The first one, let's call it p (like package), is structured as a setuptools package (i.e. with setup.py, all requirements etc., however it is not uploaded to pypi or any other online repository). The second one, let's call it s (like script), is just a python script along with two modules.

Project s is (in PyCharm) configured to use a dedicated virtualenv, let's call it venv.

The problem I have is the following: when I install the project (package) p in venv like this:

$ source /path/to/venv/bin/activate (venv)$ cd /path/to/p (venv)$ python3 setup.py develop 

in PyCharm in project s, import p statements are errorneous with message No module named p. However, when I run the script in s, everything is fine, the only problem is the PyCharm IDE complaining about not being able to find the module. I can live with this but it is very annoying...

Why does this happen? Is it a PyCharm thing or packaging related thing? See NEWS below.


The project/package p has the following structure:

p/ | +- p/ |  | |  +- __init__.py |  +- other subpackages, modules, etc. +- setup.py +- README, DESCRIPTION, setup.cfg, etc. 

When I configure the PyCharm project p to live in its own virtualenv and install it there in development mode, everything works fine.


NEWS

This problem is still present in PyCharm 5.0.4. However, I managed to solve it, kind-of.

For some reasons I had to install another package from pypi. I did it through PyCharm by going to File -> Settings -> Project: -> Project Interpreter, there clicking on the green +, finding the package and pressing the Install Package button. After the installation, the package installed by python3 setup.py develop is well recognized by PyCharm. Obviously the problem was that PyCharm didn't have some cache in sync with reality.

So the new question is, can PyCharm be told to update its caches regarding the used python environment?

like image 781
zegkljan Avatar asked Oct 04 '14 13:10

zegkljan


People also ask

Why is PyCharm not importing modules?

Troubleshooting: Try installing/importing a package from the system terminal (outside of PyCharm) using the same interpreter/environment. In case you are using a virtualenv/conda environment as your Project Interpreter in PyCharm, it is enough to activate that environment in the system terminal and then do the test.

Why packages are not installing in PyCharm?

The most viable troubleshooting action is to try installing the problematic package on the selected Python interpreter using the terminal. If you get an identical error message, then the problem is not in the IDE and you should review the rationales and typical cases, or search for a solution on the Internet.

How do I add a module to project PyCharm?

Go into File → Settings → Project Settings → Project Interpreter. Then press configure interpreter, and navigate to the "Paths" tab. Press the + button in the Paths area. You can put the path to the module you'd like it to recognize.


2 Answers

As of Pycharm 2016.1.4 (professional edition), it seems that opening a different project (e.g. through Open Recent) and then opening the original one makes Pycharm reindex the installed packages and hence recognize the develop-installed packages.

This is enough for me.

like image 114
zegkljan Avatar answered Sep 29 '22 22:09

zegkljan


In the project pane, the directory which holds p needs to be marked as source. Available under: Right-click -> "Mark Directory As" -> "Sources Root".

Note: This setting will also add it to PYTHONPATH during execution from the run menu if the corresponding check box for the option is checked in "Edit Configurations" (default).

like image 35
mike Avatar answered Sep 29 '22 23:09

mike