Pipenv无法识别Pyenv版本?

时间:2018-07-05 23:11:56

标签: python pyenv pipenv

我已经安装了Python 3.7.0,但是对于特定的Django项目,我想使用Python 3.6.5。为此,在我的Macbook Pro上使用pyenv,先运行+----+-----------+---------+--------+---------+ | id | name | surname | dad_id | mom_id | +----+-----------+---------+--------+---------+ | 1 | John | Smith | 2 | 3 | | 2 | Arnold | Smith | 7 | 8 | | 3 | Margaret | Smith | 5 | 6 | | 4 | Junior | Smith | 1 | 9 | +----+-----------+---------+--------+---------+ ,然后运行brew install pyenv,然后在项目的根目录中运行pyenv install 3.6.5。我已验证Python版本pyenv local 3.6.5是否处于活动状态:

3.6.5

我使用的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

但是,当我运行[[source]] url = "https://pypi.org/simple" verify_ssl = true name = "pypi" [packages] [dev-packages] [requires] python_version = "3.6.5" 时,我发现它“默认”为我的系统版本python 3.7.0:

pipenv shell

现在,如果我尝试运行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$ 来运行Django项目的外壳程序,我会得到一个python manage.py shell,我怀疑它与Python 3.7有密切关系,因为我确信它在以前已经起作用了: / p>

SyntaxError

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

(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 pipenv是否彼此不兼容?

4 个答案:

答案 0 :(得分:10)

Pipenv知道Pyenv,但是除非您告诉它这样做,否则它不会自动使用相同的Python版本。 Pipenv docs中有关于此的注释。

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

pipenv install --python 3.6.5

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

export PIPENV_PYTHON="$PYENV_ROOT/shims/python"

答案 1 :(得分:3)

在将系统范围的Python从3.7.0降级到3.6.5并仍然出现相同的错误后,我注意到了问题所在。 pipenv创建虚拟环境后,将不会根据您当前的pyenv版本对其进行更改,但是如果您删除了虚拟环境并创建了一个新的虚拟环境,它将“拾取”正确的版本。

答案 2 :(得分:0)

使用library(dplyr) recode(call$Name, `Mikey Mouse` = 'BFF', `Rocky Balboa` = 'Dad', `Uma Thurman` = 'Mom', .default = 'Other')

安装python 3.6.5

将新安装的python版本导出到PATH

set.seed(24) call <- data.frame(Name = sample(c('Mikey Mouse', 'Rocky Balboa', 'Uma Thurman', 'Richard Gere', 'Rick Perry'), 25, replace = TRUE)) nm1 <- c('Mickey Mouse', 'Rocky Balboa', 'Uma Thurman')

“密码锁”中的现在指定相同版本。

pyenv install 3.6.5

最后,运行删除先前的virtualenv并再次重建。

export PATH=${PYENV_PYTHON_VERSIONS_HOME}/3.6.5/bin

[requires] python_version = "3.6.5"

答案 3 :(得分:0)

就我而言,在MacOS上。我以这种方式安装了python 3.6.5:

使用pyenv安装特定的python版本:

pyenv install 3.6.5

使用带有pipenv参数的--python和python版本的位置来创建环境:

pipenv --python /Users/<<Your_User>>/.pyenv/versions/3.6.5/bin/python3.6

如果遇到与_sqlite3有关的问题,可以检查此pyenv ticket以获得解决方案。

使用pipenv run在创建的环境中执行命令:

pipenv run python manage.py shell