我的安装要求失败:
» pipenv --python 3.6.4 install
Creating a virtualenv for this project…
Using /home/myuser/.pyenv/versions/3.6.4/bin/python3.6m to create virtualenv…
⠋Running virtualenv with interpreter /home/myuser/.pyenv/versions/3.6.4/bin/python3.6m
Using base prefix '/home/myuser/.pyenv/versions/3.6.4'
New python executable in /home/myuser/.local/share/virtualenvs/svc-J_VF07t3/bin/python3.6m
Also creating executable in /home/myuser/.local/share/virtualenvs/svc-J_VF07t3/bin/python
Please make sure you remove any previous custom paths from your /home/myuser/.pydistutils.cfg file.
Installing setuptools, pip, wheel...done.
Virtualenv location: /home/myuser/.local/share/virtualenvs/svc-J_VF07t3
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
n2.7/site-packages/pipenv/resolver.py", line 11, in <module>
import pipenv.utils
File "/home/myuser/.local/lib/python2.7/site-packages/pipenv/../pipenv/__init__.py", line 17, in <module>
from .cli import cli
File "/home/myuser/.local/lib/python2.7/site-packages/pipenv/../pipenv/cli.py", line 10, in <module>
import delegator
File "/home/myuser/.local/lib/python2.7/site-packages/pipenv/vendor/delegator.py", line 8, in <module>
from pexpect.popen_spawn import PopenSpawn
File "/home/myuser/.local/lib/python2.7/site-packages/pipenv/vendor/pexpect/popen_spawn.py", line 14, in <module>
from Queue import Queue, Empty # Python 2
ModuleNotFoundError: No module named 'Queue'
/home/myuser/.local/lib/python2.7/site-packages/pipenv/utils.py:1147: ResourceWarning: Implicitly cleaning up <TemporaryDirectory '/tmp/pipenv-cLTIqh-requirements'>
warnings.warn(warn_message, ResourceWarning)
为什么选择 Python 2.7
?让我们检查虚拟环境中使用的 Python 版本:
» pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
. /home/myuser/.local/share/virtualenvs/svc-J_VF07t3/bin/activate
» . /home/myuser/.local/share/virtualenvs/svc-J_VF07t3/bin/activate
» python --version
Python 3.6.4
没错!那么 pipenv
本身呢:
» which pipenv
/home/myuser/.local/bin/pipenv
看起来问题出在于,虽然我的
virtualenv
使用的是Python 3
,但是pipenv
本身使用的是Python 2
(系统Python)。pipenv
已经按照推荐方式安装,使用的是系统范围内的python解释器:pip install --user pipenv
它确实已经安装并被找到:
» which pipenv
/home/myuser/.local/bin/pipenv
» pipenv --version
pipenv, version 11.1.3
如果被强制按照我的项目所使用的Python解释器重新安装pipenv
,那将毫无意义。
为什么在虚拟环境中安装包时,pipenv
会使用系统Python而不是使用该虚拟环境的Python?我该如何解耦pipenv
使用的Python解释器和我的项目使用的Python解释器?