pyenv python2 version not working
Asked Answered
A

3

11

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?

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.

Albina answered 8/5, 2018 at 2:55 Comment(0)
L
20

On macOS Mojave 10.14.3, I encountered a similar error that was resolved by running

$ pyenv shell 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. Note, without --use-npm, when yarn was the package manager used and there was no error.

Here is the error raised by --use-npm that was resolved by $ pyenv shell 3.7.1 2.7.15

> [email protected] 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

Lazor answered 26/1, 2019 at 6:8 Comment(0)
F
16

This error means you tried to invoke python2, but it cannot find the python2 command. 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.

You will need to activate the environments first before you can use them, e.g.:

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.

Fourdrinier answered 8/5, 2018 at 3:32 Comment(1)
Confirmed this works; python will be python2 and python3 will be python3.Mercury
E
2

You can set up locally (to your current folder) the default version for the python command to whatever version you need.

In your case, you can run:

pyenv local 2.7.8

This will create a hidden file called .python-version in your current folder. With this, pyenv is going to use this file to configure the version associated with the python command. In short, from that folder and any other under it, python will execute python 2.7.8.

Empty answered 14/8, 2018 at 23:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.