如何在其模块搜索路径中不包含〜/.local/lib/pythonX.Y/site-packages的情况下运行python [英] How to run python without including ~/.local/lib/pythonX.Y/site-packages in its module search path

查看:189
本文介绍了如何在其模块搜索路径中不包含〜/.local/lib/pythonX.Y/site-packages的情况下运行python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在~/.local/lib/python2.7/site-packages/子目录下安装了一些软件包,该软件包用于系统python(/usr/bin/python).现在,我刚刚安装了Anaconda python(也是python 2.7,但次要版本11). Anaconda发行版的整个想法是拥有一个自包含的python环境,这样每个模块都位于anaconda安装树中.

I have some packages installed under my ~/.local/lib/python2.7/site-packages/ subdir, which was for use with system python (/usr/bin/python). Now I have just installed Anaconda python (which is also python 2.7, but minor version 11). The whole idea of Anaconda distro is to have a self-containing python environment, such that EVERY module resides within anaconda install tree.

但是让我烦恼的是,由于某种原因,尽管我没有PYTHONPATH环境变量,但我无法从sys.path中禁用~/.local/lib/python2.7/site-packages/的包含.是否可以运行python可执行文件(在本例中为Anaconda的python可执行文件),而不必在python搜索路径中隐式添加~/.local/lib/python2.7/site-packages/及其下面的鸡蛋?

But what annoys me is that for some reason I cannot disable inclusion of ~/.local/lib/python2.7/site-packages/ from sys.path although I did not have PYTHONPATH environment variable. Is it possible to run python executable (in this case, Anaconda's python executable) without having to implicitly add ~/.local/lib/python2.7/site-packages/ and the eggs underneath it in the python search path?

为什么这个问题?不幸的是,~/.local/lib/python2.7/site-packages/easy-install.pth还包含对/usr/lib/python2.7/dist-packages的引用,这导致仍在搜索该系统范围的dist-packages.

Why this problem? Unfortunately the ~/.local/lib/python2.7/site-packages/easy-install.pth also contains a reference to /usr/lib/python2.7/dist-packages, which causes this system-wide dist-packages to still be searched for.

推荐答案

好,python可执行文件中有一个-s标志,用于禁止搜索用户站点目录(`〜/.local/lib/python2.7/site -包装等).那解决了上面的问题!

Well, there is a -s flag in python executable to disable searching the user site directory (`~/.local/lib/python2.7/site-packages etc). That solves the problem above!

这篇关于如何在其模块搜索路径中不包含〜/.local/lib/pythonX.Y/site-packages的情况下运行python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆