项目中使用的Python解释器与pipenv使用的Python解释器如何耦合?

6

我的安装要求失败:

» 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解释器?

1个回答

0

我曾经遇到过非常类似的问题。当我在使用pipenv和新版本的Python 3时,它开始出现。虽然这听起来并不是很有帮助,但解决方法是打开一个新的shell(而不是源shell),然后调用pipenv shell,我的python manage.py命令也能正常工作。

顺便说一下,我的错误是在字符串插值'%d' % foo中一直抱怨Python 2.7,但在Python 3中可以正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接