pyenv python2版本不起作用

3 python pyenv

我在终端中看到了这一点:

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
Run Code Online (Sandbox Code Playgroud)

我非常困惑这意味着什么。我pyenv该如何配置才能正常工作?

我正在寻找这样做:

python => version 2.7
python2 => version 2.7
python3 => version 3.6.4
Run Code Online (Sandbox Code Playgroud)

python3配置良好,但python / python2却不行,我不知道为什么。

Pen*_*ian 8

此错误表示您尝试调用 python2,但找不到 python2 命令。它还有助于告诉您该命令存在于 2.7.5 和 2.7.8 环境中,它们当前未处于活动状态。

您需要先激活环境,然后才能使用它们,例如:

pyenv shell 2.7.8 3.6.4
Run Code Online (Sandbox Code Playgroud)

我相信因为 2.7.8 首先列出,它将被“python”命令使用。


Ric*_*ood 6

在macOS Mojave 10.14.3上,我遇到了类似的错误,该错误已通过运行解决

$ pyenv外壳3.7.1 2.7.15

我在尝试$ npx create-react-app my_app --use-npm在默认情况下已安装并使用yarn的系统上运行时遇到此问题。请注意,如果不使用--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
. . .
Run Code Online (Sandbox Code Playgroud)

有关解决方案的更多详细信息:

$ 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
Run Code Online (Sandbox Code Playgroud)

GitHub问题https://github.com/electron-userland/electron-builder/issues/638引导我解决了这个问题