【问题标题】:pyenv python2 version not workingpyenv python2版本不工作
【发布时间】:2018-05-08 02:55:41
【问题描述】:

我在终端中看到了这个:

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 不是,我不知道为什么。

【问题讨论】:

    标签: python pyenv


    【解决方案1】:

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

    $ pyenv shell 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 引导我找到了这个解决方案来解决我的问题

    【讨论】:

      【解决方案2】:

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

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

      pyenv shell 2.7.8 3.6.4
      

      我相信因为首先列出了 2.7.8,所以“python”命令会使用它。

      【讨论】:

        【解决方案3】:

        您可以在本地(到当前文件夹)将python 命令的默认版本设置为您需要的任何版本。

        在你的情况下,你可以运行:

        pyenv local 2.7.8
        

        这将在您的当前文件夹中创建一个名为 .python-version 的隐藏文件。有了这个,pyenv 将使用这个文件来配置与python 命令关联的版本。简而言之,从该文件夹及其下的任何其他文件夹中,python 将执行 python 2.7.8。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多