I have a bunch of unittests that import stuff not from /python2.7/site-packages/
but from a completely different directory. So what I do is do some monkey-patching in each test file with sys.path.append
to make my Python see what I need.
Is there a way to append sys.path
globally for the whole Pycharm project without bothering with each and every file?
UPDATE:
setting default working directory doesn't help. For example, if I set the working directory to /Users/1111/_projects/_empty_dir/
like so:
and then run this
import sys
for p in sys.path: print p
what I see is this
/Users/1111/.virtualenvs/blesk/bin/python /Users/1111/_projects/_testing_pycharm/importer.py
/Users/1111/_projects/_testing_pycharm
/Users/1111/.virtualenvs/blesk/lib/python2.7/site-packages/six-1.9.0-py2.7.egg
/Users/1111/.virtualenvs/blesk/lib/python2.7/site-packages/parse-1.6.6-py2.7.egg
/Users/1111/_projects/_testing_pycharm
/Users/1111/.virtualenvs/blesk/lib/python27.zip
/Users/1111/.virtualenvs/blesk/lib/python2.7
/Users/1111/.virtualenvs/blesk/lib/python2.7/plat-darwin
/Users/1111/.virtualenvs/blesk/lib/python2.7/plat-mac
/Users/1111/.virtualenvs/blesk/lib/python2.7/plat-mac/lib-scriptpackages
/Users/1111/.virtualenvs/blesk/lib/python2.7/lib-tk
/Users/1111/.virtualenvs/blesk/lib/python2.7/lib-old
/Users/1111/.virtualenvs/blesk/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/1111/.virtualenvs/blesk/lib/python2.7/site-packages
Process finished with exit code 0
and there is no /Users/1111/_projects/_empty_dir/
on sys.path
.
sys. path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module. When a module(a module is a python file) is imported within a Python file, the interpreter first searches for the specified module among its built-in modules.
To fill in the list, click the browse button, or press Shift+Enter and specify the desired set of environment variables in the Environment Variables dialog. , and type the desired name and value. , and paste them into a text file. Select one of the pre-configured Python interpreters from the list.
This is one fairly easy, follow this path:
<your project name>
sys.path
for
'show paths for the selected interpreter'
There is now a better way to do it. You can Mark Directory as
as Sources root
. This option will appear in the bottom when you right click on any directory in Project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With