Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install any Python version on MacOS #1348

Open
kesh5 opened this issue May 28, 2019 · 21 comments
Open

Unable to install any Python version on MacOS #1348

kesh5 opened this issue May 28, 2019 · 21 comments

Comments

@kesh5
Copy link

@kesh5 kesh5 commented May 28, 2019

I'm unable to install any version of python on MacOS 10.14.4 running pyenv version 1.2.11.

This is the output:

python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.7.0...
python-build: use readline from homebrew

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

Inspect or clean up the working tree at /var/folders/mw/0ddksqyn4x18lbwftnc5dg0w0000gn/T/python-build.20190528163135.60751
Results logged to /var/folders/mw/0ddksqyn4x18lbwftnc5dg0w0000gn/T/python-build.20190528163135.60751.log

Last 10 log lines:
./Modules/posixmodule.c:5924:9: warning: this function declaration is not a prototype [-Wstrict-prototypes]
    if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
        ^
./Modules/posixmodule.c:6018:11: error: implicit declaration of function 'forkpty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    pid = forkpty(&master_fd, NULL, NULL, NULL);
          ^
./Modules/posixmodule.c:6018:11: warning: this function declaration is not a prototype [-Wstrict-prototypes]
2 warnings and 2 errors generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....

Things I have tried:

brew install readline xz
brew install openssl
xcode-select --install
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
brew remove binutils

Uninstalling and reinstalling pyenv.

All to no avail.

This is the output from pyenv doctor

Cloning /Users/XXXX/.pyenv/plugins/pyenv-doctor/bin/.....
Installing python-pyenv-doctor...
python-build: use readline from homebrew
Installed python-pyenv-doctor to /var/folders/mw/0ddksqyn4x18lbwftnc5dg0w0000gn/T/pyenv-doctor.20190528163711.69762/prefix

Congratulations! You are ready to build pythons!
@joshfriend

This comment has been minimized.

Copy link
Member

@joshfriend joshfriend commented May 28, 2019

please provide the info requested in the issue template so we can debug further.

@joshfriend joshfriend closed this May 28, 2019
@kesh5

This comment has been minimized.

Copy link
Author

@kesh5 kesh5 commented May 28, 2019

Prerequisite

  • Make sure your problem is not listed in the common build problems.
  • Make sure no duplicated issue has already been reported in the pyenv issues. You should look for closed issues, too.
  • Make sure you are not asking us to help solving your specific issue.
    • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
  • Make sure your problem is not derived from packaging (e.g. Homebrew).
    • Please refer to the package documentation for the installation issues, etc.
  • Make sure your problem is not derived from plugins.
    • This repository is maintaining pyenv and the default python-build plugin only. Please refrain from reporting issues of other plugins here.

Description

@joshfriend

This comment has been minimized.

Copy link
Member

@joshfriend joshfriend commented May 29, 2019

C Compiler information: Mac Mojave Default

what is this? please run clang --version and post the results

Python version: Python 3.7.0

Do any newer versions of 3.7 install? Like 3.7.3 for example? A google search of the error message from your log turned up this python bugreport which looks like it has been fixed. Maybe there's a patch from that report that needs to be applied to 3.7.0 specifically

@joshfriend joshfriend reopened this May 29, 2019
@kesh5

This comment has been minimized.

Copy link
Author

@kesh5 kesh5 commented May 29, 2019

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Not even the newer versions are installing.

@usmcfiredog

This comment has been minimized.

Copy link

@usmcfiredog usmcfiredog commented May 30, 2019

I am having this same exact issue I am on macOS 10.14.5

@omdv

This comment has been minimized.

Copy link

@omdv omdv commented Jun 6, 2019

Same here.

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

macOS 10.14.5

Last 10 log lines:
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/y6/6k21n5fn2zz4x0myzfk5zn100000gn/T/python-build.20190605212530.3148/Python-3.7.2':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

pyenv doctor

Cloning .pyenv/plugins/pyenv-doctor/bin/.....
Installing python-pyenv-doctor...
python-build: use readline from homebrew
Installed python-pyenv-doctor to /var/folders/y6/6k21n5fn2zz4x0myzfk5zn100000gn/T/pyenv-doctor.20190605213730.11988/prefix

Congratulations! You are ready to build pythons!
@georgalis

This comment has been minimized.

Copy link

@georgalis georgalis commented Jun 9, 2019

BTW "configure: error: C compiler cannot create executables" makes me think this could be related to a Mojave security feature... is your terminal program listed in System Preferences -> Security & Privacy -> Privacy -> Full Disk Access

@omdv

This comment has been minimized.

Copy link

@omdv omdv commented Jun 11, 2019

@georgalis yes, my terminal (iterm) has Full Disk Access.

@georgalis

This comment has been minimized.

Copy link

@georgalis georgalis commented Jun 11, 2019

@omdv I've been frustrated by this error before... is your OS and Xcode all updated? looks like macOS 10.14.4 should be 10.14.5, the error could come from incomplete or wrong versioned headers.

@omdv

This comment has been minimized.

Copy link

@omdv omdv commented Jun 11, 2019

Yep, everything is up-to-date and no issues with anything otherwise. Here is the error with 10.14.5 as well, freshly generated :)

UILD FAILED (OS X 10.14.5 using python-build 1.2.8-83-g2350e57b)

Inspect or clean up the working tree at /var/folders/y6/6k21n5fn2zz4x0myzfk5zn100000gn/T/python-build.20190611164005.20270
Results logged to /var/folders/y6/6k21n5fn2zz4x0myzfk5zn100000gn/T/python-build.20190611164005.20270.log

Last 10 log lines:
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/y6/6k21n5fn2zz4x0myzfk5zn100000gn/T/python-build.20190611164005.20270/Python-3.7.2':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.
@georgalis

This comment has been minimized.

Copy link

@georgalis georgalis commented Jun 11, 2019

Well, not knowing your system history, your level of experience, being remote and reasonably certain this is nothing to do with pyenv. You could check env to be sure there is nothing unusual in your environment (PATH, CFLAGS, etc). My next suggestion may seem heavy handed, since the problem is build environment, libs or tools, a reinstall of Xcode will insure they are okay.

@georgalis

This comment has been minimized.

Copy link

@georgalis georgalis commented Jun 20, 2019

@omdv any progress? when I've had the error, C compiler cannot create executables it was because I had some compiler packages installed but not all of them (on linux). For Mac a reinstall of Xcode should cover that. What is your "OS architecture (e.g. amd64):" run uname -m

@omdv

This comment has been minimized.

Copy link

@omdv omdv commented Jul 5, 2019

@georgalis deleting Xcode.app, and reinstalling pyenv and Xcode command line tools helped.

@mgomesborges

This comment has been minimized.

Copy link

@mgomesborges mgomesborges commented Jul 12, 2019

Hey @georgalis @kesh5 @omdv @usmcfiredog any progress?
This problem broke my macOS dev setup tutorial =(

I found a workaround to fix it. You can find it at devsetup_macos_tutorial.md

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.0

I use PYTHON_CONFIGURE_OPTS="--enable-framework" to fix a bug with Matplotlib.

@tabulon

This comment has been minimized.

Copy link

@tabulon tabulon commented Jul 23, 2019

Following the solution from @marcosgomesborges, and adding another workaround for the OpenSSL issue mentioned elsewhere, below is the gist of what I had to put together (in my .bashrc) to get pyenv python builds working on macOS 10.14 (Mojave):

# Towards the end of ".bashrc", I have got:

# The usual  `pyenv init` stuff
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi

if [[ "$(uname -s)"  == "Darwin" ]] ; then

  # Adopted SDK workaround from @marcosgomesborges
  [[ -n "$MACOSX_DEPLOYMENT_TARGET"  ]]  || export MACOSX_DEPLOYMENT_TARGET="$(sw_vers -productVersion | cut -c -5)"    # e.g.: 10.14
  [[ -n "$SDKROOT" ]]                    || export SDKROOT="$(xcrun --show-sdk-path)"

  # Workaround for OpenSSL header/library paths (for GCC & LINKER)
  pfx_openssl="$(brew --prefix openssl)"  # Change this if openssl was not installed via homebrew 
  if [[ -d "$pfx_openssl" ]]  ; then
      export CPATH="${pfx_openssl}/include:${CPATH}"                # Headers for C pre-processor
      export LIBRARY_PATH="${pfx_openssl}/lib:${LIBRARY_PATH}"      # libraries (for the linker)
  fi

fi

The above may or may not work for macOS versions other than 10.14 (Mojave) (but I don't see any reason why it shouldn't).

However, please note that the above assumes you have installed openssl via homebrew. Otherwise, you will need to assign the appropriate directory path to pfx_opensslaccordingly.


UPDATE @ 2020-02-06:

Depending on the case, you may also need to set the environment variable AR just for running pyenv install... Or otherwise, solve the problem in a more persistent manner, as suggested below...

which -a ar   # should just print :  `/usr/bin/ar` (or at least print in the first position)

# if the above prints multiple paths for the archiver, or something other than the default system path for `ar` (which should be `/usr/bin/ar`)
# try setting the path for the `ar`(archiver) program via environment variable:
AR=/usr/bin/ar pyenv install ...

# If that works, you may want to solve the problem in a more persistent way, which would would usually mean following homebrew's original wise advise.
# WARNING:  The below may end up breaking other stuff elsewhere, though... Murphy's Laws... 
# If that's the case, you can always go back to the temporray solution (of setting AR only for pyenv) mentioned above. 

brew unlink binutils   # If you had installed previously installed (and LINKED) the `binutils` package via homebrew (which would have installed `ar`) 

This solves another problem you may encounter when building python on MacOS. (This one does NOT appear to be related to pyenv in any way, but it would prevent pyenv install from succeeding (as that's what it essentially does, i.e. build and install a particular version of the python binary)...

Anyhow, the problem manifests itself with errors during the linking stage:

ld: warning: ignoring file libpython3.8.a, file was built for archive which is not the architecture being linked (x86_64): libpython3.8.a
ld: warning: ignoring file libpython3.8.a, file was built for archive which is not the architecture being linked (x86_64): libpython3.8.a
Undefined symbols for architecture x86_64:
  "_Py_BytesMain", referenced from:
      _main in python.o
ld: symbol(s) not found for architecture x86_64
Undefined symbols for architecture x86_64:

It turns out, I had an other incarnation of the ar (archiver) program early in my PATH, that I must have installed the "binutils" package with homebrew...
Normally, homebrew leaves such packages "keg ONLY", and advises NOT to link them because they could interfere with the equivalents that come with the macOS system... I had probably ignored that advise (for some reason, I do not recall)... Interfere it did...

@corymosiman12

This comment has been minimized.

Copy link

@corymosiman12 corymosiman12 commented Jul 26, 2019

Platform information: macOS 10.14.6
OS architecture (e.g. amd64): x86_64
pyenv version: pyenv 1.2.13
Python version: 2.7.10
Python3 version: Python 3.7.4

I am also unable to get any version of python to install via pyenv. Any help appreciated. Things I have tried:

brew install readline xz
brew install openssl
xcode-select --install
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Added the above from @tabulon to my '.bash_profile':

# The usual  `pyenv init` stuff
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
  eval "$(pyenv virtualenv-init -)"
fi

if [[ "$(uname -s)"  == "Darwin" ]] ; then

  # Adopted SDK workaround from @marcosgomesborges
  [[ -n "$MACOSX_DEPLOYMENT_TARGET"  ]]  || export MACOSX_DEPLOYMENT_TARGET="$(sw_vers -productVersion | cut -c -5)"    # e.g.: 10.14
  [[ -n "$SDKROOT" ]]                    || export SDKROOT="$(xcrun --show-sdk-path)"

  # Workaround for OpenSSL header/library paths (for GCC & LINKER)
  pfx_openssl="$(brew --prefix openssl)"  # Change this if openssl was not installed via homebrew 
  if [[ -d "$pfx_openssl" ]]  ; then
      export CPATH="${pfx_openssl}/include:${CPATH}"                # Headers for C pre-processor
      export LIBRARY_PATH="${pfx_openssl}/lib:${LIBRARY_PATH}"      # libraries (for the linker)
  fi

fi

Tried to update pyenv to HEAD as suggested here

Tried to:

$ brew remove binutils
Error: No such keg: /usr/local/Cellar/binutils
env | grep FLAG
LDFLAGS=-L/usr/local/opt/readline/lib -L/usr/local/opt/openssl/lib -L/usr/local/Cellar/zlib/1.2.11/lib
XPC_FLAGS=0x0
CFLAGS=-I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/usr/local/Cellar/zlib/1.2.11/include

python-build.20190726153016.11910.log

EDIT
Also tried reinstalling pyenv via brew:

brew reinstall pyenv

It seems I don't have:

pyenv doctor
pyenv: no such command `doctor'
@mgomesborges

This comment has been minimized.

Copy link

@mgomesborges mgomesborges commented Jul 27, 2019

@corymosiman12 this problem can be caused by an incomplete migration or old library version. Are you using macports?

Maybe removing ranlib from /opt/local/bin and using system /usr/bin/ranlib fix the issue:

# Remove/backup ranlib
sudo mv /opt/local/bin/ranlib /opt/local/bin/ranlib-backup
sudo mv /opt/local/bin/ar     /opt/local/bin/ar-backup

Maybe removing cctools can help as well:

# Upgrade brew
brew upgrade

#Remove cctools
brew uninstall -f cctools

Then just try to install Python 3.6.5:

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.5
@corymosiman12

This comment has been minimized.

Copy link

@corymosiman12 corymosiman12 commented Jul 27, 2019

Thanks @marcosgomesborges! Seemed moving the ranlib stuff worked. Also removed cctools as well, but it worked after just moving the ranlib stuff - much appreciated!

It appears I do have MacPorts installed...do you recommend uninstalling? Is there a safe way to do so?

@treuille

This comment has been minimized.

Copy link

@treuille treuille commented Dec 17, 2019

This worked for me:

rm -fv ~/.pyenv/shims/clang* ~/.pyenv/shims/llvm* 

Then I was able to:

pyenv install 3.8.0
@peterbe

This comment has been minimized.

Copy link

@peterbe peterbe commented Feb 19, 2020

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk MACOSX_DEPLOYMENT_TARGET=10.15 PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.6

worked for me. The only difference from the "same" tip above was that I used 10.15 instead of 10.4 :)

@k-oguma

This comment has been minimized.

Copy link

@k-oguma k-oguma commented Mar 1, 2020

I'm same the as follows too.
#1348 (comment)
#1348 (comment)

In my case, the installation was completed as follows.

Environment

% sw_vers | grep -i product
ProductName:    Mac OS X
ProductVersion: 10.14.6

Preparation

% brew install llvm zlib
% exec $SHELL -l

% export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
% export CPPFLAGS="-I/usr/local/opt/zlib/include"
# Or these flags add into your rc (run commands) file (e.g. ~/.bashrc or ~/.zshrc or other.)

% printenv| egrep "CPP|LDFLAGS"
CPPFLAGS=-I/usr/local/opt/zlib/include
LDFLAGS=-L/usr/local/opt/zlib/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib

Try & check

% pyenv install 3.7.2

% pyenv whence python
3.7.2
% python --version
Python 3.7.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.