[英]How can I create a python virtual environment that only includes one version of python/pip?
I had been under the impression that if I created a python environment with a specific python version, it would use just that version, but it seems I was mistaken:我的印象是,如果我使用特定的 python 版本创建 python 环境,它将只使用该版本,但似乎我错了:
$ /usr/bin/python3 -m venv pyenv
$ ls pyenv
$ ls pyenv/bin
activate activate.fish easy_install pip pip3.8 python3
activate.csh Activate.ps1 easy_install-3.8 pip3 python
Is there any reason why older versions of python need to exist alongside the current one in my venv?为什么旧版本的 python 需要与我的 venv 中的当前版本一起存在? And can I specify not to, or should I just manually delete the python2/pip?
我可以指定不这样做,还是应该手动删除 python2/pip?
In your virtual environment, all the python*
executables will point to the same version.在您的虚拟环境中,所有
python*
可执行文件都将指向相同的版本。 You can see this from the symbolic links:您可以从符号链接中看到这一点:
$ /usr/bin/python3 -m venv pyenv
$ cd pyenv/bin
$ ls -l python*
lrwxrwxrwx 1 [user] [group] 7 May 28 05:49 python -> python3
lrwxrwxrwx 1 [user] [group] 16 May 28 05:49 python3 -> /usr/bin/python3
Similarly all the pip
executables will be copies of the same file:同样,所有
pip
可执行文件将是同一文件的副本:
$ ls -l pip*
-rwxr-xr-x 1 [user] [group] 212 May 28 05:49 pip
-rwxr-xr-x 1 [user] [group] 212 May 28 05:49 pip3
-rwxr-xr-x 1 [user] [group] 212 May 28 05:49 pip3.6
$ diff3 pip*
[no output]
This means, for example, that once you have run the activate
script so that this bin
directory is in your PATH
, you will find the python
in your virtual environment regardless of whether you type python
or python3
.这意味着,例如,一旦您运行了
activate
脚本,以便此bin
目录位于您的PATH
中,无论您键入python
还是python3
,您都会在虚拟环境中找到python
。
The same is true of python scripts which you invoke with #!/usr/bin/env python
or #!/usr/bin/env python3
for example.例如,您使用
#!/usr/bin/env python
或#!/usr/bin/env python3
调用的 python 脚本也是如此。
Only if you explicitly invoke a different version of python (for example python2
) or give a full path to the python executable (for example /usr/bin/python
) might you find another version located elsewhere on your system.只有当您显式调用 python 的不同版本(例如
python2
)或提供 python 可执行文件的完整路径(例如/usr/bin/python
)时,您可能会在系统的其他位置找到另一个版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.