![](/img/trans.png)
[英]Setting global python version with pyenv is not working as expected
[英]pyenv python2 version not working
我在终端中看到了这一点:
gyp ERR! stack pyenv: python2: command not found
gyp ERR! stack
gyp ERR! stack The `python2' command exists in these Python versions:
gyp ERR! stack 2.7.5
gyp ERR! stack 2.7.8
我非常困惑这意味着什么。 我该如何配置pyenv
使其起作用?
我正在寻找这样做:
python => version 2.7
python2 => version 2.7
python3 => version 3.6.4
python3配置良好,但python / python2却不行,我不知道为什么。
此错误表示您尝试调用python2,但找不到python2命令。 它也可以有帮助地告诉您该命令存在于2.7.5和2.7.8环境中,这些环境当前未激活。
您需要先激活环境,然后才能使用它们,例如:
pyenv shell 2.7.8 3.6.4
我相信,因为首先列出了2.7.8,所以它将被“ python”命令使用。
在macOS Mojave 10.14.3上,我遇到了类似的错误,该错误已通过运行解决
$ pyenv外壳3.7.1 2.7.15
我在尝试在默认情况下安装并使用yarn的系统上运行$ npx create-react-app my_app --use-npm
时遇到此问题。 请注意,如果没有--use-npm
,则当yarn是程序包管理器使用时,没有错误。
这是--use-npm
引发的错误,已由$ pyenv shell 3.7.1 2.7.15
解决。
> fsevents@1.2.4 install /Users/richardlogwood/dev/react/my_app/node_modules/fsevents
> node install
gyp ERR! configure error
gyp ERR! stack Error: Command failed: /Users/richardlogwood/.pyenv/shims/python2 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack pyenv: python2: command not found
gyp ERR! stack
gyp ERR! stack The `python2' command exists in these Python versions:
gyp ERR! stack 2.7.15
gyp ERR! stack
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack at ChildProcess.emit (events.js:188:13)
gyp ERR! stack at maybeClose (internal/child_process.js:978:16)
gyp ERR! stack at Socket.stream.socket.on (internal/child_process.js:395:11)
gyp ERR! stack at Socket.emit (events.js:188:13)
gyp ERR! stack at Pipe._handle.close (net.js:610:12)
gyp ERR! System Darwin 18.2.0
. . .
有关解决方案的更多详细信息:
$ pyenv versions
system
2.7.15
* 3.7.1 (set by /Users/richardlogwood/.pyenv/version)
$ pyenv shell 3.7.1 2.7.15
$ pyenv versions
system
* 2.7.15 (set by PYENV_VERSION environment variable)
* 3.7.1 (set by PYENV_VERSION environment variable)
$ pyenv shell
3.7.1:2.7.15
# now create-react-app succeeds!
npx create-react-app my_app --use-npm
GitHub问题https://github.com/electron-userland/electron-builder/issues/638引导我解决了这个问题
您可以在本地(到当前文件夹)将python
命令的默认版本设置为所需的任何版本。
就您而言,您可以运行:
pyenv local 2.7.8
这将在当前文件夹中创建一个名为.python-version
的隐藏文件。 这样, pyenv
将使用此文件来配置与python
命令关联的版本。 简而言之, python
将在该文件夹及其下的任何其他文件夹中执行python
2.7.8。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.