Kur*_*eek 4 python pyenv pipenv
我安装了Python 3.7.0,但对于特定的Django项目,我想使用Python 3.6.5.使用pyenv此目的,在我的MacBook Pro我跑brew install pyenv,其次pyenv install 3.6.5,在项目的根目录下,pyenv local 3.6.5.我已经验证Python版本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)
Run Code Online (Sandbox Code Playgroud)
在Pipfile我使用的是类似以下内容:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
[dev-packages]
[requires]
python_version = "3.6.5"
Run Code Online (Sandbox Code Playgroud)
但是,当我运行时pipenv shell,我得到它'默认'到我的系统版本,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$
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试运行python manage.py shellDjango项目的shell,我得到一个SyntaxError我怀疑与Python 3.7密切相关的东西,因为我确信它之前有效:
(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
Run Code Online (Sandbox Code Playgroud)
然而,我认为其根本原因在于它是在Python 3.7.0中运行而不是在Python 3.6.5中运行.
是pipenv与pyenv不是"兼容"彼此?
eve*_*een 12
Pipenv知道Pyenv,但它不会自动使用相同的Python版本,除非你告诉它这样做.在Pipenv文档中有一个关于此的说明.
您可以告诉Pipenv使用特定的Python版本,例如
pipenv install --python 3.6.5
Run Code Online (Sandbox Code Playgroud)
或者您可以将环境变量设置为默认为Pyenv版本,例如
export PIPENV_PYTHON="$PYENV_ROOT/shims/python"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2233 次 |
| 最近记录: |