Pipenv 无法识别 Pyenv 版本? [英] Pipenv not recognizing Pyenv version?

查看:83
本文介绍了Pipenv 无法识别 Pyenv 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 Python 3.7.0,但对于特定的 Django 项目,我想使用 Python 3.6.5.为此使用 pyenv,在我的 Macbook Pro 上我运行了 brew安装pyenv,然后是pyenv install 3.6.5,然后在项目根目录下pyenv local 3.6.5.我已经验证 Python 版本 3.6.5 处于活动状态:

I have Python 3.7.0 installed, but for a specific Django project, I would like to use Python 3.6.5. Using pyenv for this purpose, on my Macbook Pro I ran brew install pyenv, followed by pyenv install 3.6.5 and, in the project's root directory, pyenv local 3.6.5. I've verified that Python version 3.6.5 is active:

Kurts-MacBook-Pro-2:lucy-web kurtpeek$ cat .python-version
3.6.5
Kurts-MacBook-Pro-2:lucy-web kurtpeek$ pyenv versions
  system
* 3.6.5 (set by /Users/kurtpeek/Documents/dev/lucy2/lucy-web/.python-version)

我使用的 Pipfile 类似于以下内容:

The Pipfile I'm using is similar to the following:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.6.5"

但是,当我运行 pipenv shell 时,我发现它默认"为我的系统版本 python 3.7.0:

However, when I run pipenv shell, I get that it 'defaults' to my system version, python 3.7.0:

Kurts-MacBook-Pro-2:lucy-web kurtpeek$ pipenv shell
Loading .env environment variables...
Warning: Your Pipfile requires python_version 3.6.5, but you are using 3.7.0 (/Users/k/.local/share/v/l/bin/python).
  $ pipenv check will surely fail.
Launching subshell in virtual environment…
bash-3.2$  . /Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/bin/activate
(lucy-web-CVxkrCFK) bash-3.2$

现在,如果我尝试运行 python manage.py shell 来运行 Django 项目的 shell,我会得到一个 SyntaxError,我怀疑它与 Python 3.7 密切相关,因为我确定这以前有效:

Now, if I try to run python manage.py shell to run the Django project's shell, I get a SyntaxError which I suspect is germane to Python 3.7, since I'm sure this was working before:

(lucy-web-CVxkrCFK) bash-3.2$ python manage.py shell
Traceback (most recent call last):
  File "manage.py", line 28, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/two_factor/apps.py", line 10, in ready
    from .admin import patch_admin
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/two_factor/admin.py", line 2, in <module>
    from django.contrib import admin
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/contrib/admin/__init__.py", line 4, in <module>
    from django.contrib.admin.filters import (
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/contrib/admin/filters.py", line 10, in <module>
    from django.contrib.admin.options import IncorrectLookupParameters
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/contrib/admin/options.py", line 12, in <module>
    from django.contrib.admin import helpers, widgets
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/django/contrib/admin/widgets.py", line 151
    '%s=%s' % (k, v) for k, v in params.items(),
    ^
SyntaxError: Generator expression must be parenthesized

然而,我认为其根本原因是它在 Python 3.7.0 中运行,而不是在 Python 3.6.5 中运行.

The root cause of this, however, I believe is that it is being run in Python 3.7.0 and not in Python 3.6.5 as desired.

pipenvpyenv 不是兼容"的吗?

Are pipenv and pyenv not 'compatible' with each other?

推荐答案

Pipenv 知道 Pyenv,但它不会自动使用相同的 Python 版本,除非您告诉它这样做.Pipenv 文档.

Pipenv is aware of Pyenv, but it doesn't automatically use the same Python version unless you tell it to do that. There is a note about this in the Pipenv docs.

您可以告诉 Pipenv 使用特定的 Python 版本,例如

You can either tell Pipenv to use a specific Python version, like

pipenv install --python 3.6.5

或者您可以将环境变量设置为默认为 Pyenv 版本,例如

or you can set an environment variable to default to the Pyenv version, like

export PIPENV_PYTHON="$PYENV_ROOT/shims/python"

这篇关于Pipenv 无法识别 Pyenv 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆