我有一堆单元测试,它们不是从 /python2.7/site-packages/ 而是从一个完全不同的目录导入东西.所以我要做的是在每个测试文件中用 sys.path.append 做一些猴子补丁,让我的 Python 看到我需要的东西.
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.
有没有一种方法可以为整个 Pycharm 项目全局附加 sys.path 而不用打扰每个文件?
Is there a way to append sys.path globally for the whole Pycharm project without bothering with each and every file?
更新:设置默认工作目录没有帮助.例如,如果我将工作目录设置为 /Users/1111/_projects/_empty_dir/ 像这样:
UPDATE: setting default working directory doesn't help. For example, if I set the working directory to /Users/1111/_projects/_empty_dir/ like so:
然后运行这个
import sys for p in sys.path: print p我看到的是这个
/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并且 sys.path 上没有 /Users/1111/_projects/_empty_dir/.
推荐答案这是一个相当简单的方法,请遵循以下路径:
This is one fairly easy, follow this path:
更多推荐
如何在pycharm中全局管理sys.path
发布评论