Python中文
首页
教程
问答
标签
搜索
登录
注册
在pycharm中如何全局管理sys.path
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有很多unittests,它们不是从<code>/python2.7/site-packages/</code>而是从完全不同的目录导入内容。所以我要做的是用<code>sys.path.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a></code>在每个测试文件中做一些猴子补丁,让我的Python知道我需要什么。</p> <p>有没有一种方法可以为整个Pycharm项目全局附加<code>sys.path</code>,而不必为每个文件操心?</p> <p>更新: 设置默认工作目录没有帮助。例如,如果我将工作目录设置为<code>/Users/1111/_projects/_empty_dir/</code>,如下所示:</p> <p><img src="https://i.stack.imgur.com/u86XN.png" alt="screenshot"/></p> <p>然后运行这个</p> <pre><code>import sys for p in sys.path: print p </code></pre> <p>我看到的是</p> <pre><code>/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 </code></pre> <p>在<code>sys.path</code>上没有<code>/Users/1111/_projects/_empty_dir/</code>。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>这是一个相当简单的方法,遵循以下路径:</p> <ol> <li>设置</li> <li>项目:</li> <li>项目翻译</li> <li>选择要为其更新sys.path的解释器</li> <li>找到右下角的图标,“显示所选解释器的路径”</li> <li>将文件夹添加到路径列表中。</li> </ol>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
文本导入时标题行中的特殊字符
5 回答
文本小部件:在没有输入时更新并在循环后保持空闲
2 回答
文本小部件tkin
5 回答
文本小部件tkinter中的标签更改或文本外观更改是否有撤消功能?
4 回答
文本小部件tkinter复制图像选项
3 回答
文本小部件上的Python Tkinter ttk滚动条未缩放
5 回答
文本小部件上的滚动条可能需要根据制表符ord显示前进行滚动
4 回答
文本小部件不显示lis中的内容
6 回答
文本小部件不显示Unicode字符
4 回答
文本小部件中写入的行间距
3 回答
文本小部件中的文本作为变量
7 回答
文本小部件中的滚动条仅显示在底部
2 回答
文本小部件中的选项卡键空间计数
10 回答
文本小部件作为Lis
8 回答
文本小部件在主框架中扩展列宽
10 回答
文本小部件未使用删除功能清除
2 回答
文本小部件滚动动画(Tkinter、Python)
8 回答
文本居中。格式正确吗?
3 回答
文本差分算法
2 回答
文本已知时音频文件中的单词索引
9 回答