如果用户在活动的“ virtualenv”下工作时尝试创建python 3“ venv”,则将无法正确创建最终的虚拟环境。
如下所示, venv
和virtualenv
环境都是使用python 3的“ venv”模块创建的。 但是,后者是在活动的outer
virtualenv下创建的,缺少许多二进制文件以及其site-packages目录的内容。 python -m pip
确实起作用。
设定:
[vagrant@vagrant-arch ~]$ python3.6 -m venv venv
[vagrant@vagrant-arch ~]$ virtualenv -p python3.6 outer
[vagrant@vagrant-arch ~]$ source outer/bin/activate
(outer) [vagrant@vagrant-arch ~]$ python -m venv virtualenv
bin
内容:
[vagrant@vagrant-arch ~]$ ls venv/bin/
activate activate.csh activate.fish easy_install easy_install-3.6 pip pip3 pip3.6 python python3 python3.6
[vagrant@vagrant-arch ~]$ ls virtualenv/bin/
activate activate.csh activate.fish python python3
site-packages
内容:
[vagrant@vagrant-arch ~]$ ls venv/lib/python3.6/site-packages/
__pycache__ easy_install.py pip pip-9.0.1.dist-info pkg_resources setuptools setuptools-28.8.0.dist-info
[vagrant@vagrant-arch ~]$ ls virtualenv/lib/python3.6/site-packages/
[vagrant@vagrant-arch ~]$
事实证明python -m pip
“有效的”,但是它将软件包安装到原始的virtualenv中。
(outer) [vagrant@vagrant-arch ~]$ deactivate
[vagrant@vagrant-arch ~]$ source virtualenv/bin/activate
(virtualenv) [vagrant@vagrant-arch ~]$ python -m pip install tox
是活动性静脉,应含有毒素
(virtualenv) [vagrant@vagrant-arch ~]$ ls virtualenv/lib/python3.6/site-packages/
(virtualenv) [vagrant@vagrant-arch ~]$ ls virtualenv/bin/
activate activate.csh activate.fish python python3
但是tox已安装到原始virtualenv
(virtualenv) [vagrant@vagrant-arch ~]$ ls outer/lib/python3.6/site-packages/
__pycache__ pip pkg_resources pluggy-0.5.2.dist-info py-1.4.34.dist-info setuptools-36.6.0.dist-info six.py tox-2.9.1.dist-info virtualenv.py wheel
easy_install.py pip-9.0.1.dist-info pluggy py setuptools six-1.11.0.dist-info tox virtualenv-15.1.0.dist-info virtualenv_support wheel-0.30.0.dist-info
(virtualenv) [vagrant@vagrant-arch ~]$ ls outer/bin
activate activate.csh activate.fish activate_this.py easy_install easy_install-3.6 pip pip3 pip3.6 python python-config python3 python3.6 tox tox-quickstart virtualenv wheel
我尝试用--copies
选项创建类似的venv,但是没有效果。
在这里也可以做到这一点: https :
我怀疑需要从venv
一侧进行修复以进行.real_prefix
舞蹈。 我将针对pre-commit
的缘故,研究该方法作为解决方法
这似乎是BPO问题: https ://bugs.python.org/issue30811
我怀疑需要从venv一侧进行修复以进行
.real_prefix
舞蹈。
我不清楚应由谁负责修复。 venv
检测到它是在virtualenv
内部执行的,还是virtualenv
创建一个与venv
兼容的环境? 一方面, virtualenv
早于venv
。 另一方面, venv
是标准库的一部分。
无论如何,这是我目前在tox-venv中使用的解决方法:
可执行路径检测可以改进,因为它当前仅查找python3
。 例如,您可能需要python3.6
,但是python3
指向python3.4
。
我选择了类似的解决方法: https :
(主要区别是预提交已经进行了一些标准化,因此我使用bin/$(basename exe)
而不是bin/python3
)
嗯,是的,总的来说,我觉得我们应该兼容venv。
@gaborbernat根据berdario / pew#173,似乎并非如此。 @uranusjr关心报时吗?
由于此问题最近没有活动,因此已被自动标记为陈旧。 如果没有进一步的活动,它将关闭。 如果您想保持打开状态,只需添加一条评论即可。 感谢您的贡献。
@gaborbernat我认为应该将该问题重命名为“在virtualenv内运行venv”,以区别于#1339。
@FranklinYu更新的标题是否足够?
现在已如火如荼地在#1366中作废。
最有用的评论
我不清楚应由谁负责修复。
venv
检测到它是在virtualenv
内部执行的,还是virtualenv
创建一个与venv
兼容的环境? 一方面,virtualenv
早于venv
。 另一方面,venv
是标准库的一部分。无论如何,这是我目前在tox-venv中使用的解决方法:
https://github.com/tox-dev/tox-venv/blob/58401663fda66dfba4f344553525c73d57432d5e/src/tox_venv/hooks.py#L10 -L49
可执行路径检测可以改进,因为它当前仅查找
python3
。 例如,您可能需要python3.6
,但是python3
指向python3.4
。