我在一个最新的Debian测试版上安装了pyenv,并且在其中安装了Python 2.7.1。
我使用这个版本创建了一个虚拟环境,但是当激活它时,它给我显示的是Python系统版本(3.7)。
以下是我所做的操作:
$ pyenv virtualenv 2.7.16 my_project-2.7
Requirement already satisfied: virtualenv in /home/user/.local/lib/python2.7/site-packages (15.1.0)
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Using base prefix '/usr'
New python executable in /home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/bin/python
Installing setuptools, pip, wheel...
done.
Installing pip from https://bootstrap.pypa.io/get-pip.py...
Collecting pip
Using cached https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.1.1
Uninstalling pip-19.1.1:
Successfully uninstalled pip-19.1.1
Successfully installed pip-19.1.1
$ pyenv activate my_project-2.7
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
$ python --version
Python 3.7.3
$ pip --version
pip 19.1.1 from /home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/lib/python3.7/site-packages/pip (python 3.7)
很奇怪。virtualenv已经正确设置在~/.pyenv/version/2.7.16中,但我发现pip来自/home/user/.pyenv/versions/2.7.16/envs/my_project-2.7/lib/python3.7/。
我认为我错过了一些东西,或者我可能在我的python安装中搞砸了,但我找不出python3.7库在这里做什么。
我如何为python2.7创建此virtualenv?
编辑
我尝试完全删除pyenv(删除$(pyenv root)目录),然后使用pyenv-installer重新安装它,但没有任何变化。
我为我有的两个项目创建了两个virtualenvs(上面的2.7和一个是3.5)。
$ pyenv virtualenvs
2.7.16/envs/my_project-2.7 (created from /usr)
3.6.8/envs/other_project-3.6 (created from /home/user/.pyenv/versions/3.6.8)
my_project-2.7 (created from /usr)
other_project-3.6 (created from /home/user/.pyenv/versions/3.6.8)
我认为问题可能在于这个从 /usr 创建,但我不明白这是什么意思。为什么这个虚拟环境不是从 pyenv 的 python 版本创建的?这是否有任何相关性?
看起来当我创建一个3.+ 的虚拟环境时,使用了 venv。但在2.7上,使用的是 virtualenv 并失败了。
pyenv
和pyenv-virtualenv
,那么 WFM 就能正常工作。 - ivan_pozdeev