简体   繁体   English

pyenv python2版本不起作用

[英]pyenv python2 version not working

I am seeing this in my terminal: 我在终端中看到了这一点:

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

I am super confused what this means. 我非常困惑这意味着什么。 How can I configure pyenv so that this works? 我该如何配置pyenv使其起作用?

I am looking to do this: 我正在寻找这样做:

python => version 2.7
python2 => version 2.7
python3 => version 3.6.4

python3 is configured fine, but python/python2 are not and I can't figure out why. python3配置良好,但python / python2却不行,我不知道为什么。

This error means you tried to invoke python2, but it cannot find the python2 command. 此错误表示您尝试调用python2,但找不到python2命令。 It is also helpfully telling you that the command exists in the 2.7.5 and 2.7.8 environments, which are not currently active. 它也可以有帮助地告诉您该命令存在于2.7.5和2.7.8环境中,这些环境当前未激活。

You will need to activate the environments first before you can use them, eg: 您需要先激活环境,然后才能使用它们,例如:

pyenv shell 2.7.8 3.6.4

I believe that because 2.7.8 is listed first, that will get used by the "python" command. 我相信,因为首先列出了2.7.8,所以它将被“ python”命令使用。

On macOS Mojave 10.14.3, I encountered a similar error that was resolved by running 在macOS Mojave 10.14.3上,我遇到了类似的错误,该错误已通过运行解决

$ pyenv shell 3.7.1 2.7.15 $ pyenv外壳3.7.1 2.7.15

I encountered this issue trying to run $ npx create-react-app my_app --use-npm on a system where yarn is installed and being used by default. 我在尝试在默认情况下安装并使用yarn的系统上运行$ npx create-react-app my_app --use-npm时遇到此问题。 Note, without --use-npm , when yarn was the package manager used and there was no error. 请注意,如果没有--use-npm ,则当yarn是程序包管理器使用时,没有错误。

Here is the error raised by --use-npm that was resolved by $ pyenv shell 3.7.1 2.7.15 这是--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
. . .

More details about the solution: 有关解决方案的更多详细信息:

$ 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

I was led to this solution for my problem by this GitHub issue https://github.com/electron-userland/electron-builder/issues/638 GitHub问题https://github.com/electron-userland/electron-builder/issues/638引导我解决了这个问题

You can set up locally (to your current folder) the default version for the python command to whatever version you need. 您可以在本地(到当前文件夹)将python命令的默认版本设置为所需的任何版本。

In your case, you can run: 就您而言,您可以运行:

pyenv local 2.7.8

This will create a hidden file called .python-version in your current folder. 这将在当前文件夹中创建一个名为.python-version的隐藏文件。 With this, pyenv is going to use this file to configure the version associated with the python command. 这样, pyenv将使用此文件来配置与python命令关联的版本。 In short, from that folder and any other under it, python will execute python 2.7.8. 简而言之, python将在该文件夹及其下的任何其他文件夹中执行python 2.7.8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM