asdf-community / asdf-python

Python plugin for the asdf version manager
https://github.com/asdf-vm/asdf
MIT License
656 stars 56 forks source link

Error installing Python on OS X Mojave #43

Closed geowa4 closed 5 years ago

geowa4 commented 5 years ago

I tried installing both 3.7.1 and 3.6.7 with the same result shown below. It seems Mojave may have removed zlib: https://stackoverflow.com/questions/48288658/zipimport-zipimporterror-cant-decompress-data-zlib-not-available#comment92859734_50370494.

asdf install python 3.6.7
python-build 3.6.7 /Users/geowa4/.asdf/installs/python/3.6.7
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.7.tar.xz...
-> https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz
Installing Python-3.6.7...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14 using python-build 1.2.7-11-g835707da)

Inspect or clean up the working tree at /var/folders/p6/2v_qbpvs41dd7yq9c3g2cqvh0000gn/T/python-build.20181026220617.38974
Results logged to /var/folders/p6/2v_qbpvs41dd7yq9c3g2cqvh0000gn/T/python-build.20181026220617.38974.log

Last 10 log lines:
  File "/private/var/folders/p6/2v_qbpvs41dd7yq9c3g2cqvh0000gn/T/python-build.20181026220617.38974/Python-3.6.7/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/p6/2v_qbpvs41dd7yq9c3g2cqvh0000gn/T/python-build.20181026220617.38974/Python-3.6.7/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/p6/2v_qbpvs41dd7yq9c3g2cqvh0000gn/T/python-build.20181026220617.38974/Python-3.6.7/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/p6/2v_qbpvs41dd7yq9c3g2cqvh0000gn/T/python-build.20181026220617.38974/Python-3.6.7/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
koenbollen commented 5 years ago

I had the same issue.

My workaround:

$ brew install zlib
$ export LDFLAGS="-L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="-I/usr/local/opt/zlib/include"
$ export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
$ export KEEP_BUILD_PATH=true
$ asdf install python 3.7.1

(this succeeds for me)

geowa4 commented 5 years ago

Thanks, that worked for me as well!

evantravers commented 5 years ago

I also am getting similar problems…

❯ asdf install python 3.7.1
python-build 3.7.1 /Users/evan/.asdf/installs/python/3.7.1
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.1.tar.xz...
-> https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
Installing Python-3.7.1...
python-build: use readline from homebrew
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems

BUILD FAILED (OS X 10.14 using python-build 1.2.8)

Inspect or clean up the working tree at /var/folders/5_/f2f8clnd4zd7gd6tf7zm4jn00000gn/T/python-build.20181105161823.78561
Results logged to /var/folders/5_/f2f8clnd4zd7gd6tf7zm4jn00000gn/T/python-build.20181105161823.78561.log

Last 10 log lines:
            install|*) ensurepip="" ;; \
        esac; \
         ./python.exe -E -m ensurepip \
            $ensurepip --root=/ ; \
    fi
Looking in links: /var/folders/5_/f2f8clnd4zd7gd6tf7zm4jn00000gn/T/tmp0ib4qurm
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
koenbollen commented 5 years ago

@evantravers Try installing openssl from homebrew using brew install openssl. Might do the trick.

esselius commented 5 years ago

Using mac os 10.14 Mojave

Not sure what fixed this for me, but I ran these things in this order:

$ asdf install python 3.7.1
# FAIL: "Missing the zlib?"

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
$ asdf install python 3.7.1
# FAIL: "Missing the OpenSSL lib?"

$ brew install -s python
# FAIL: "Please reinstall readline. Sorry :("

$ brew reinstall readline
$ brew install -s python
# SUCCESS

$ brew uninstall python
$ asdf install python 3.7.1
# SUCCESS
jamilbk commented 5 years ago

When you install zlib from Homebrew it gives you a hint:

% brew install zlib
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
No changes to formulae.

==> Downloading https://homebrew.bintray.com/bottles/zlib-1.2.11.mojave.bottle.tar.gz
Already downloaded: /Users/jamil/Library/Caches/Homebrew/downloads/01ac92cf18f86708cd068eaf9a3594a15b31861eca1e4d6718563d5e27acd6b2--zlib-1.2.11.mojave.bottle.tar.gz
==> Pouring zlib-1.2.11.mojave.bottle.tar.gz
==> Caveats
zlib is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

For compilers to find zlib you may need to set:
  export LDFLAGS="-L/usr/local/opt/zlib/lib"
  export CPPFLAGS="-I/usr/local/opt/zlib/include"

==> Summary
🍺  /usr/local/Cellar/zlib/1.2.11: 12 files, 373KB

So on my Mac with 10.14.1 I just needed the following:

export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
asdf install python 3.6.7
dipnlik commented 5 years ago

I was having the SSL issue even after trying brew reinstall readline and other suggestions and brew reinstall -s python solved it, even without brew uninstall python. Not sure if -s was really required or not.

Noticed that brew install python also installs pkg-config so maybe this package is related to the issue? It is a little weird having to install Homebrew's python to be able to install asdf's python.

MrPaulAR commented 5 years ago

I too am having issues and hoping someone sees the error in my ways.

asdf install python 3.6.8                                                                                                        1247ms  Fri Jan  4 10:53:13 2019
python-build 3.6.8 /Users/paulthomas/.asdf/installs/python/3.6.8
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.8.tar.xz...
-> https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
Installing Python-3.6.8...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14.2 using python-build 1.2.8-12-g775a4b63)

Inspect or clean up the working tree at /var/folders/lf/zzyy185j7bzd9c540qp_46ww0000gp/T/python-build.20190104105327.83497
Results logged to /var/folders/lf/zzyy185j7bzd9c540qp_46ww0000gp/T/python-build.20190104105327.83497.log

Last 10 log lines:
      _test_repeated_init_and_subinterpreters in _testembed.o
  "_Py_SetProgramName", referenced from:
      _test_forced_io_encoding in _testembed.o
      _test_repeated_init_and_subinterpreters in _testembed.o
      _test_pre_initialization_api in _testembed.o
  "_Py_SetStandardStreamEncoding", referenced from:
      _test_forced_io_encoding in _testembed.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Programs/_testembed] Error 1

Below are the steps that I've done I've set the build flags as defined above for LDFLAGS, CPPFLAGS, PKG_CONFIG_PATH, & KEEP_BUILD_PATH Reinstalled zlib (brew reinstall zlib) Reinstalled pythong (brew reinstall -s python) Ran brew doctor and fixed findutils

I'm still getting the same error.

I can download the tarball from python's website and successfully compile it. I didn't install.

pikeas commented 5 years ago

Same issue under Mojave 10.14.2 when install Python 3.7.2. Tinkered with adding openssl/zlib via homebrew and various compiler flags but it wasn't enough. I eventually gave up and installed Python via homebrew instead of asdf.

danhper commented 5 years ago

asdf-python is simply wrapping pyenv's python-build. For build errors, please check pyenv issue tracker. If it works with python-build but not with asdf-python please open another issue or comment here.

mividtim commented 3 years ago

@danhper The fix everyone is using for python-build is to export LDFLAGS and CPPFLAGS env vars to point to zlib installed with Homebrew, and re-run the Python install. However, running this plugin, it seems that these env vars are ignored - it always uses the zlib from xcode:

python-build: use zlib from xcode sdk

This seems like it's in your court to fix. asdf-python won't work on a brand-new Mac laptop. Will you help us out, or just point the finger elsewhere?

Virviil commented 3 years ago

Here is the solution that worked for me:

https://github.com/pyenv/pyenv/issues/1737#issuecomment-765724815

So it's possible to add the flag to asdf also:

CFLAGS=-Wno-implicit-function-declaration asdf install python 3.6.0