好吧,它变得复杂。针对Ubuntu Xenial(我使用的Linux Mint的基础版本)显示了以下内容。让我们解决一下:
pyvenv
它指的是Python 3.3+ stdlib软件包的包装器脚本。但是从Python 3.6开始不推荐使用。
它也是一个PyPi软件包,它是一个虚拟环境切换器。
静脉
这是Python 3.3+ stdlib软件包,其目的是改进和替换PyPi virtualenv软件包(请参阅PEP 405)。但是似乎还不存在(至少还没有完成功能)。
python-virtualenv和virtualenv
$ apt-cache show virtualenv | grep Depends
Depends: python3, python3-virtualenv
如您所见,它在Python 3上运行。package的python-virtualenv
使用方式类似于python2 -m virtualenv py2
。让我们看看如何virtualenv
在全新的Ubuntu Xenial(docker run --rm -it ubuntu:xenial
)上工作:
$ virtualenv
bash: virtualenv: command not found
$ apt-get update
...
$ apt-get install --yes --no-install-recommends virtualenv
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ca-certificates dh-python libexpat1 libmpdec2 libpython3-stdlib
libpython3.5-minimal libpython3.5-stdlib libsqlite3-0 libssl1.0.0
mime-support openssl python-pip-whl python3 python3-minimal
python3-pkg-resources python3-virtualenv python3.5 python3.5-minimal
Suggested packages:
libdpkg-perl python3-doc python3-tk python3-venv python3-setuptools
python3.5-venv python3.5-doc binutils binfmt-support
Recommended packages:
file
The following NEW packages will be installed:
ca-certificates dh-python libexpat1 libmpdec2 libpython3-stdlib
libpython3.5-minimal libpython3.5-stdlib libsqlite3-0 libssl1.0.0
mime-support openssl python-pip-whl python3 python3-minimal
python3-pkg-resources python3-virtualenv python3.5 python3.5-minimal
virtualenv
...
$ virtualenv test
The executable python2 (from --python=python2) does not exist
$ virtualenv -p python3 py3
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /py3/bin/python3
Also creating executable in /py3/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ . py3/bin/activate
(py3) $ python --version
Python 3.5.2
(py3) $ deactivate
$ apt-get install --yes --no-install-recommends python
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libffi6 libpython-stdlib libpython2.7-minimal libpython2.7-stdlib
python-minimal python2.7 python2.7-minimal
Suggested packages:
python-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
libffi6 libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python
python-minimal python2.7 python2.7-minimal
...
$ virtualenv py2
Running virtualenv with interpreter /usr/bin/python2
New python executable in /py2/bin/python2
Also creating executable in /py2/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ . py2/bin/activate
(py2) $ python --version
Python 2.7.12
如您所见,即使virtualenv
package正在使用python3-virtualenv
,它的默认值是创建Python 2环境。