我已经安装了Python 3.7.0版本,但是针对一个特定的Django项目,我想使用Python 3.6.5版本。为此目的,我在我的Macbook Pro上使用pyenv
,运行了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)
我正在使用的 Pipfile
与以下内容类似:
[[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:
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有关,因为我确定以前是可以工作的:
(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。
pipenv
和pyenv
之间是否不“兼容”?
PIPEVN_PYTHON
的使用方式与其预期不符。请参阅此评论。 - smac89