【发布时间】:2018-12-07 20:43:10
【问题描述】:
在我的 MacBook Pro 上,我默认使用 Python 3.6,但我从另一个项目接管的项目需要 2.7,我通过 Anaconda 安装了它。我使用pipenv install 设置了 Pipenv,将版本设置为 3.6。然后我尝试通过以下方式更改版本:
pipenv --python 2.7
但它返回了这个警告:
Warning: Your Pipfile requires python_version 3.6, but you are using 2.7.15 (/Users/j/.local/share/v/Z/bin/python).
那么pipenv check当然失败了,又返回了:
Specifier python_version does not match 3.6 (2.7).
然后我尝试了pipenv install python 2.7.15,也失败了。 Pipfile 保持 3.6 不变。
Error: An error occurred while installing 2.7.15!
Could not find a version that satisfies the requirement 2.7.15 (from versions: )
No matching distribution found for 2.7.15
这里是python版本ls -ls /usr/bin/python*
32 -rwxr-xr-x 1 root wheel 66880 24 Oct 12:47 /usr/bin/python
0 -rwxr-xr-x 4 root wheel 925 18 Aug 02:45 /usr/bin/python-config
0 lrwxr-xr-x 1 root wheel 75 8 Oct 21:45 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
0 lrwxr-xr-x 1 root wheel 82 8 Oct 21:45 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
32 -rwxr-xr-x 1 root wheel 66880 24 Oct 12:47 /usr/bin/pythonw
0 lrwxr-xr-x 1 root wheel 76 8 Oct 21:45 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
请建议我如何使用 Pipenv 将这个特定项目的 python 从 3.6 切换到 2.7?
一切顺利,
嘉君
【问题讨论】:
-
请阅读该解决方案。我相信你可以在那里找到答案。 stackoverflow.com/questions/49794432/…
-
好吧,哪个是您的系统范围的 python 并不重要。我只是不明白你的问题到底是什么。如果 pipfile 中的 python 版本是 3.6,但你想要 2.7,为什么不能将 pipfile 中的 3.6 更改为 2.7?
-
@Sraw,我尝试直接将 Pipfile 更改为 2.7。但是 sys.version 仍然返回 3.6
-
您更改该文件,然后将您的 pipenv 的 env 也更改为 2.7。所以你可以使用 2.7 而不会检查失败。由于您之前检查失败,我相信您知道如何更改为 2.7。