I had a python project with a lot of imports like:
from src.main.fr.some.module import someclass
and it was working good but my colleagues wanted the imports to be like:
from fr.some.module import someclass
Then I changed the PYTHONPATH
in the activate
script of my virtualenv
like:
export PYTHONPATH="/home/giffon/Documents/wopmars/src/main:/home/giffon/Documents/wopmars/src/test"
and replaced all the src.main.fr.some.module
with fr.some.module
.
Then I tried my code in the console and the output was good (note that I am printing the PYTHONPATH
at the beginning of my code and /home/giffon/Documents/wopmars/src/main
appears like expected).
(WopMars)giffon@CZC0507G5C-HP-Z400:~/Documents/wopmars/src/main/fr/tagc/wopmars/framework/parsing$ python3 Parser.py
PRINTING THE PYTHONPATH
/home/giffon/Documents/wopmars/src/main/fr/tagc/wopmars/framework/parsing
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/pyparsing-2.1.4-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/cycler-0.10.0-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/pytz-2016.4-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/python_dateutil-2.5.3-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/six-1.10.0-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/numpy-1.11.0-py3.4-linux-x86_64.egg
/home/giffon/Documents/wopmars/src/main
/home/giffon/Documents/wopmars/src/test
/home/giffon/virtualenvs/WopMars/lib/python3.4
/home/giffon/virtualenvs/WopMars/lib/python3.4/plat-x86_64-linux-gnu
/home/giffon/virtualenvs/WopMars/lib/python3.4/lib-dynload
/usr/lib/python3.4
/usr/lib/python3.4/plat-x86_64-linux-gnu
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages
Reading the definition file... -> done.
Checking whether the file is well formed... -> done.
Building the execution DAG... -> done.
Writing the dot file... -> done.
But, since I am working with pycharm, I wanted the IDE to take my changes into account. And here comes the issues.
I read somewhere that I should modify the interpreter Python Path by doing the following:
File > Settings > Projet:wopmars > Projet Interpreter > "wheel" > More... > "Show path for the selected interpreter (WopMars interpreter selected)" > + > "Browse to /home/giffon/Documents/wopmars/src/main" > Ok > Ok > Apply > Ok
And then I execute the same code than above:
/home/giffon/virtualenvs/WopMars/bin/python3 /home/giffon/Documents/wopmars/src/main/fr/tagc/wopmars/framework/parsing/Parser.py
PRINTING THE PYTHONPATH
/home/giffon/Documents/wopmars/src/main/fr/tagc/wopmars/framework/parsing
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/pyparsing-2.1.4-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/cycler-0.10.0-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/pytz-2016.4-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/python_dateutil-2.5.3-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/six-1.10.0-py3.4.egg
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages/numpy-1.11.0-py3.4-linux-x86_64.egg
/home/giffon/Documents/wopmars/src/test
/home/giffon/Documents/wopmars/src/main
/home/giffon/virtualenvs/WopMars/lib/python3.4
/home/giffon/virtualenvs/WopMars/lib/python3.4/plat-x86_64-linux-gnu
/home/giffon/virtualenvs/WopMars/lib/python3.4/lib-dynload
/usr/lib/python3.4
/usr/lib/python3.4/plat-x86_64-linux-gnu
/home/giffon/virtualenvs/WopMars/lib/python3.4/site-packages
Traceback (most recent call last):
File "/home/giffon/Documents/wopmars/src/main/fr/tagc/wopmars/framework/parsing/Parser.py", line 12, in <module>
from fr.tagc.wopmars.framework.management.DAG import DAG
ImportError: No module named 'fr.tagc.wopmars.framework.management.DAG'
You probably noticed that the /home/giffon/Documents/wopmars/src/main
appears in the PYTHONPATH
meaning that the configuration of pycharm
interpreter's path has been taken into account. So, the interpreter knows where to find modules but can't see fr
... any idea for solving this issue?
It is probably not interesting for solving this issue but the error-raising code is:
print("PRINTING THE PYTHONPATH")
for p in sys.path:
print(p)
print("\n\n")
from fr.tagc.wopmars.framework.management.DAG import DAG
Note: changing PYTHONPATH
in .profile
or .bashrc
gave me the same results
Note2: if I don't export PYTHONPATH, the console give me the same error than pycharm