试图让生活恢复到陷入困境的django包中。他们使用tox进行测试,因此我在MacBook上设置了pyenv。我已经安装了python的3个版本,如下所示,所有内容看起来都应该可以使用,但是如果是的话,我不会问为什么不可以。
我已经用〜替换了主目录,以便于阅读。
pyenv与brew install pyenv
一起安装,而各种版本的python与pyenv install #.#.#
一起安装
垫片存在:
$ echo $PATH
~/.pyenv/shims:~/.platformsh/bin:/usr/local/sbin:...
$ which python3.6
~/.pyenv/shims/python3.6
$ which python3.4
~/.pyenv/shims/python3.4
$ which python3.5
~/.pyenv/shims/python3.5
但是执行它们并不能按预期工作:
$ pyenv local 3.4.9 3.5.6 3.6.8
$ python3.4
Python 3.4.9 (default, Feb 12 2019, 10:33:47)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ python3.5
pyenv: python3.5: command not found
The `python3.5' command exists in these Python versions:
3.5.6
$ python3.6
pyenv: python3.6: command not found
The `python3.6' command exists in these Python versions:
3.6.8
毒物像这样失败:
py34-1.11: commands succeeded
ERROR: py36-1.11: Error creating virtualenv. Note that some special characters (e.g. ':' and unicode symbols) in paths are not supported by virtualenv. Error details: InvocationError("Failed to get version_info for python3.6: pyenv: python3.6: command not found\n\nThe `python3.6' command exists in these Python versions:\n 3.6.8\n\n", None)
ERROR: py36-2.0: Error creating virtualenv. Note that some special characters (e.g. ':' and unicode symbols) in paths are not supported by virtualenv. Error details: InvocationError("Failed to get version_info for python3.6: pyenv: python3.6: command not found\n\nThe `python3.6' command exists in these Python versions:\n 3.6.8\n\n", None)
py36-latest: commands succeeded
docs: commands succeeded
但是在.tox文件夹中,您会找到这些可以手动激活的VirtualEnv。
$ ls .tox
dist docs flake8 log py34-1.11 py36-1.11 py36-2.0 py36-latest
因为它在某些时候起作用。...
我确实了解为什么它不起作用的机制,我不明白的是为什么pyenv无法正确设置环境(或者也许正是它应该表现的方式)。我阅读的所有内容似乎都表明python3.6应该启动python3.6.8解释器
$ bash -x python3.6
+ set -e
+ '[' -n '' ']'
+ program=python3.6
+ [[ python3.6 = \p\y\t\h\o\n* ]]
+ export PYENV_ROOT=~/.pyenv
+ PYENV_ROOT=~/.pyenv
+ exec /usr/local/Cellar/pyenv/1.2.9/libexec/pyenv exec python3.6
pyenv: python3.6: command not found
The `python3.6' command exists in these Python versions:
3.6.8
答案 0 :(得分:0)
pyenv
默认为picks the python“本地”,即它查找PYTHON_VERSION
环境变量或.python-version
文件。
我个人觉得此设置有点麻烦(需要在所有项目中乱放这些文件,尤其是在需要多个版本的项目中)。幸运的是,您可以使用pyenv global #.#.#
在您的情况下,要使python3.6
垫片执行3.6.8
而不需要设置.python-version
文件,您可以运行pyenv global 3.6.8
-您可以运行此命令多次针对不同的python版本:pyenv global 3.6.8 3.5.6 ...
您可能没有在tox
中解决这些问题的原因是执行时Tox清除了环境,因此PYTHON_VERSION
环境变量将无法通过。您可以通过在tox.ini
中设置passenv=
来关闭此功能。例如:
[testenv]
passenv = PYTHON_VERSION