问题
While trying to install Python 3.6.6
(for Airflow
) using PyEnv
on MacOS
, I am encountering build failure with following stack-trace
File "/private/var/folders/6y/kf699bqj2sgcgjshb20fr5zh0000gn/T/python-build.20180721180716.86347/Python-3.6.6/Lib/xmlrpc/client.py", line 138, in from xml.parsers import expat File "/private/var/folders/6y/kf699bqj2sgcgjshb20fr5zh0000gn/T/python-build.20180721180716.86347/Python-3.6.6/Lib/xml/parsers/expat.py", line 4, in from pyexpat import * ModuleNotFoundError: No module named 'pyexpat' make: *** [install] Error 1
BUILD FAILED (OS X 10.13.6 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/6y/kf699bqj2sgcgjshb20fr5zh0000gn/T/python-build.20180721180716.86347 Results logged to /var/folders/6y/kf699bqj2sgcgjsh
I've followed the steps mentioned in the docs for setting-up PyEnv on Mac via Homebrew.
Environment / Framework versions
MacOS High Sierra 10.13.6
Homebrew 1.7.1
PyEnv 1.2.6
- Existing
Python
distributionsPython 2.7.15 [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Python 3.7.0 [Clang 9.0.0 (clang-900.0.39.2)] on darwin
回答1:
I had this problem with Mojave and Python 3.7.3.
This worked for me:
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 pyenv install 3.7.3
回答2:
The accepted answer didn't work for me (Mojave) but this did:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Credit to http://www.blog.howechen.com/macos-mojave-pyenv-install-multi-version-build-failed-solution/
回答3:
The only way I could get it working is through the below prefixes before installing
CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include
-I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 3.7.1
回答4:
I was able to get away with above error by referring to Common build problems
brew install readline xz
xcode-select --install
brew install openssl
After this, I installed and initialized pyenv
brew install pyenv
pyenv init
(inside your project directory)
Finally install and activate required python
version
- pyenv install 3.6.6
pyenv local 3.6.6
(inside your project directory)
Here's the link to original thread #1188 on GitHub
by @Harry Moreno
回答5:
short answer:
$ brew upgrade
now you can try to install python through pyenv
$ pyenv install 3.7.4
then, you have to set the python path
pyenv global 3.7.4
now, close and open a new terminal and write the command
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
That's all. For me it was fine.
回答6:
BUILD FAILED (OS X 10.14.3 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/kt/79hj2dxs5vg7gsy188n6tk9c0000gn/T/python-build.20190226112205.71745
Results logged to /var/folders/kt/79hj2dxs5vg7gsy188n6tk9c0000gn/T/python-build.20190226112205.71745.log
Last 10 log lines:
File "/private/var/folders/kt/79hj2dxs5vg7gsy188n6tk9c0000gn/T/python-build.20190226112205.71745/Python-3.6.6/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/private/var/folders/kt/79hj2dxs5vg7gsy188n6tk9c0000gn/T/python-build.20190226112205.71745/Python-3.6.6/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/private/var/folders/kt/79hj2dxs5vg7gsy188n6tk9c0000gn/T/python-build.20190226112205.71745/Python-3.6.6/Lib/ensurepip/__init__.py", line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/private/var/folders/kt/79hj2dxs5vg7gsy188n6tk9c0000gn/T/python-build.20190226112205.71745/Python-3.6.6/Lib/ensurepip/__init__.py", line 27, in _run_pip
import pip._internal
I found the solution from http://digidememory.blogspot.com/2019/01/macos-mojave-10142python371.html
In my case, I solved by this command
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
回答7:
In my case this was caused by migration of data from old to new Mac. Both Xcode Command Line Tools and Homebrew migrated, but something broke. Reinstalling them from scratch worked for me.
Reinstall CLI tools:
$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
Reinstall and update Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
Istall pyenv + packages and python 3:
brew install pyenv
brew install openssl readline sqlite3 xz zlib
pyenv install 3.7.5
回答8:
This worked for me:
- remove CommandLineTools folder under /Library/Developer
- run in terminal: xcode-select --install
- sudo mv /usr/local/include /usr/local/include_old
来源:https://stackoverflow.com/questions/51551557/pyenv-build-failed-installing-python-on-macos