Search code examples
pythonmacosvirtualenvpyenv

failed to install python versions using pyenv on macos


I am trying to install python 3.8.5 using pyenv on my new MacBook Pro.

I was able to install pyenv successfully and confirmed it was working fine. It is quite weird as I was able to install python 3.9.2 successfully using pyenv on my MacOS.

The problem arises when I tried to install another python version such as 3.8.5.

I get the error messages as below.

~ » pyenv install 3.8.5
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.5.tar.xz...
-> https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
Installing Python-3.8.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 11.2.2 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/gm/wv5zbtxx6gl2cbg9yszmxnzc0000gn/T/python-build.20210403160603.37920
Results logged to /var/folders/gm/wv5zbtxx6gl2cbg9yszmxnzc0000gn/T/python-build.20210403160603.37920.log

Last 10 log lines:
checking size of _Bool... 1
checking size of off_t... 8
checking whether to enable large file support... no
checking size of time_t... 8
checking for pthread_t... yes
checking size of pthread_t... 8
checking size of pthread_key_t... 8
checking whether pthread_key_t is compatible with int... no
configure: error: Unexpected output of 'arch' on OSX
make: *** No targets specified and no makefile found.  Stop.

I tried to follow some ways to resolve the issue as described in

https://github.com/pyenv/pyenv/wiki/Common-build-problems (common build problem)

However, I get the same outcome each time I try to install python versions using pyenv.

I am new to MacOS, I would like to get some advice on this. Could anyone help on this?

Thank you very much!


Solution

  • the error you are facing may be caused by an older version of the xcode command line tool. Please try typing and running the following command.It may change something.

    xcode-select --install

    LDFLAGS="-L$(xcrun --show-sdk-path)/usr/lib" pyenv install 3.8.5

    I hope it works for you.