I create a projectname package, and use PyCharm to debug the code in it.
I also use venv for setting up Python environment for the package. I follow the standard package structure as follows.
.
├── NAME
│?? ├── __init__.py
│?? ├── arith.py
│?? └── arith.py
├── bin
│?? └── app.py
├── build
│?? ├── bdist.macosx-10.11-intel
│?? └── lib
│?? └── NAME
│?? ├── __init__.py
│?? └── arith.py
├── dist
│?? └── projectname-0.1-py2.7.egg
├── docs
├── requirements.txt
├── setup.py
└── tests
├── __init__.py
?? └── arith_tests.py
Then, I imported the project into PyCharm.
In Project:sekelton, I marked NAME/tests as source folders, and build/dist as excluded folders.
I also run python setup.py install
to build and install the generated egg file into the venv's site-package directory.
The issue is that the egg file installed in site-package is called first as the PYTHONPATH shows from import sys; print sys.path
:
['/python/structure/projects/skeleton/bin',
'python/structure/projects/venv/lib/python2.7/site-packages/projectname-0.1-py2.7.egg', <== egg file is searched first
'python/structure/projects/skeleton/NAME', <==
This is pretty annoying as I can't debug the code with PyCharm, and when I modified the code, I had to run python setup.py install
again to update the egg file. I may be able to circumvent this issue by removing the egg file from the Project Interpreter setup, but I think changing the order should be the better option.
How can I change the PYTHONPATH order in PyCharm so that the local Source Folders are searched first?
EDIT
The PyCharm shows an error message when I tried to remove the package from the Project Interpreter setup, but it's false positives, as PyCharm successfully removes the egg file, and updates the easy-install.pth.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…