gue*_*tli 2 python virtualenv python-2.7 ubuntu-18.04
如果我使用Ubuntu 18.04创建virtualenv,则会local创建一个名为gets 的目录.
virtualenv test-env
cd test-env
ls -l local/
Run Code Online (Sandbox Code Playgroud)
输出:
lrwxrwxrwx 1 foo foo 30 Jan 30 10:47 bin -> /home/foo/tmp/test-env/bin
lrwxrwxrwx 1 foo foo 34 Jan 30 10:47 include -> /home/foo/tmp/test-env/include
lrwxrwxrwx 1 foo foo 30 Jan 30 10:47 lib -> /home/foo/tmp/test-env/lib
Run Code Online (Sandbox Code Playgroud)
版:
virtualenv --version
15.0.3
Run Code Online (Sandbox Code Playgroud)
这在其他机器上不会发生(例如企业SuSE Linux)
AFAIK不需要此目录.
有没有办法避免这个目录被调用local哪个不需要?
(这是关于Python 2.7)
通过文档和一些较旧的SO帖子,我偶然发现了这个答案和官方发行说明.
在我Ubuntu 16.04和virtualenv 15.0.1组合上,该~/.local文件夹包含所有与Python相关的库,文档和二进制文件.
我怀疑virtualenv试图"匹配"这种方法,以保持与裸系统上运行的脚本的兼容性,因为Python $PATH在那里寻找与Python相关的模块,包等.
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
...
/home/<username>/.local/lib/python2.7/site-packages
...
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
Run Code Online (Sandbox Code Playgroud)
如果我在virtualenv中运行相同的命令,我会在Python路径中获得两个目录.
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)
/home/<username>/python-venv-tests/lib/python2.7
/usr/lib/python2.7
...
/home/<username>/python-venv-tests/local/lib/python2.7/site-packages
/home/<username>/python-venv-tests/lib/python2.7/site-packages
...
Run Code Online (Sandbox Code Playgroud)
所以,回答你的问题
.local目录仅包含/bin, /include, /lib虚拟环境"正确" 的符号链接,因此不存在重复库的危险~/.localPython包的兼容性措施完成的$PATH如果您确实需要),但它不会对您的工作流产生任何影响(或者您计划将虚拟环境迁移到其他主机).