Virtualenv,无站点包,sys.path

Virtualenv, no-site-packages, sys.path

我的根本问题是我无法从 --no-site-packages 到 "work."

我在 SO 上阅读了一堆 posts,包括 this post。我是一个巨大的 Ubuntu 菜鸟,在 python 如何与 os.

交互方面也好不到哪儿去

其他posts建议printenv会显示PYTHONPATH 当我在我的virtualenv中时,printenv似乎没有列出"PYTHONPATH",但它相当pos我知道我应该寻找的是一个我不知道的特定 dir 而不是大写字母。

然而,我注意到,当我在 virtualenv 中 运行 python shell 时,我所有的全局包都被列出。

我不确定这是 virtualenv.bashrcUbuntu 还是 my brain 的问题。任何帮助将不胜感激。

如果有好心人、知识渊博的人愿意在反复的过程中帮助我,我将不胜感激。我没有列出我的任何输出,因为老实说,除了上述之外,我不完全确定从哪里开始。

编辑回复评论; UTC:07:41 2015 年 11 月 19 日

启动环境:

notanambiturner@computer:~/Dropbox/$$ P/...$ virtualenv --no-site-packages venv
New python executable in venv/bin/python
Installing setuptools, pip, wheel...done.

进入环境:

notanambiturner@computer:~/Dropbox/$$ P/...$ source venv/bin/activate
(venv)notanambiturner@computer:~/Dropbox/$$ P/...$

系统包:

(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ pip freeze
adium-theme-ubuntu==0.3.4
apt-xapian-index==0.46
beautifulsoup4==4.4.1
bleach==1.4.2
blinker==1.3
cffi==1.1.2
characteristic==14.3.0
chardet==2.3.0
colorama==0.3.3
command-not-found==0.3
....
virtualenv==13.1.2
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.1
wheel==0.26.0
whitenoise==1.0.6
xdiagnose==3.8.1
zope.interface==4.1.2
(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ 

sys.path:

(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
'/usr/lib/python2.7', 
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', 
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',     
'/home/notanambiturner/.local/lib/python2.7/site-packages',   
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
>>> 

您可以清楚地看到站点包包含在 sys.path 中,这非常烦人。

Python3 似乎稍微好一点,并不是说我知道如何使用 pip freeze (或者即使我可以):

(venv)notanambiturner@computer:~/Dropbox/$$ P/...$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/usr/lib/python3.4/lib-dynload',
 '/usr/local/lib/python3.4/dist-packages',
 '/usr/lib/python3/dist-packages']
>>> 

下次编辑。我的 mind is bottled 进一步。 UTC 08:00 2015 年 11 月 19 日

因为我是阴谋论者,所以我尝试在 Dropbox 之外创建一个 venv。

notanambiturner@computer:~$ source venv/bin/activate
(venv)notanambiturner@computer:~$ pip freeze
wheel==0.24.0
(venv)notanambiturner@computer:~$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02) 
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
 '/home/notanambiturner/venv/lib/python2.7',
 '/home/notanambiturner/venv/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/notanambiturner/venv/lib/python2.7/lib-tk',
 '/home/notanambiturner/venv/lib/python2.7/lib-old',
 '/home/notanambiturner/venv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/notanambiturner/venv/local/lib/python2.7/site-packages',
 '/home/notanambiturner/venv/lib/python2.7/site-packages']
    >>> 

什么……这……到底……?我的意思是,我认为这是某种进步?可能是我的文件名 (\$\$\ P/) 导致了问题?从我读过的内容来看,只要我 sudo rm -rf venv 它应该与我之前在同一目录中创建和删除 virtualenv 没有区别。是吗?

哎呀

在路径名中使用 $ 时存在错误(至少在 Ubuntu 上)。