Zum Inhalt springen

Pyenv for managing Python

After brew installation we are now ready to install Python. To make it easier i prefer pyenv which enables you to have differen python versions at once on your desktop and use the one you like.

Installation:

brew install pyenv

This command installs pyenv to your system. But you need to follow (like mentioned at the official page:

Then follow the rest of the post-installation steps under Basic GitHub Checkout, starting with #3 („Add pyenv init to your shell to enable shims and autocompletion“).

To find out (if you do not know) which shell you are using:

echo "$SHELL"

Once this is done you are ready to use pyenv

If you do have issues when e.g. using:

pyenv install 3.9.1

with an error like

configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found. Stop.

Then it seems you need to have a later version from xcode commandline installed (The gcc cannot compile the code).

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Then follow the instructions from the UI. After this you can retry with the python installation (see above)

With

pyenv versions

you can see which versions you can use and with

pyenv global 3.9.1

you can select globally the version 3.9.1

If it does not work you may have not restarted the terminal. To check: With which python there has to be a result with /shims/ in the path.

Finally

python --version