Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyenv failed to download a existing version of Python

I recently installed pyenv and attempted to install a version of python, according to a blog post. I ran some commands, but encountered an error and I am uncertain how to resolve.

$ pyenv install 3.6.6
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.6.tar.xz...
-> https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
error: failed to download Python-3.6.6.tar.xz

BUILD FAILED (OS X 10.12.6 using python-build 20180424)
like image 835
MedicineMan Avatar asked Jan 01 '19 00:01

MedicineMan


3 Answers

I got the same error. After digging the pyenv source code, I found the root cause.

Inside /usr/local/bin/python-build, it would detect a http client to download the tar file. First choice is aria2c, then curl, then wget.

So check if aria2c, curl and wget can run successfully.

detect_http_client() {
  local client
  for client in aria2c curl wget; do
    if type "$client" &>/dev/null; then
      echo "$client"
      return
    fi
  done
  echo "error: please install \`aria2c\`, \`curl\`, or \`wget\` and try again" >&2
  return 1
}

For my problem, there is something wrong with my aria2c command. I upgraded my openssl library before, then all related commands got error when execute them.

> aria2c                                                                                                                                              55.5s
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/opt/libssh2/lib/libssh2.1.dylib

After reinstall aria2c and related libraries, problem solved.

Steps to reinstall aria2c:

> brew uninstall aria2
> brew install aria2
like image 191
Han He Avatar answered Sep 27 '22 21:09

Han He


The error can have multiple reasons but you have the ability to use the

--verbose

flag to get more precise information.

pyenv install <your version> --verbose

In my case the error was curl installed via homebrew but the path was pointing to the native installation:

python-build: use [email protected] from homebrew
python-build: use readline from homebrew
/var/folders/_z/nn_xcbvd3_15l_njz9j9c85c0000gn/T/python-build.20190717020159.52739 ~
Downloading Python-3.5.7.tar.xz...
-> https://www.python.org/ftp/python/3.5.7/Python-3.5.7.tar.xz
dyld: Library not loaded: /usr/local/opt/libssh2/lib/libssh2.1.dylib
  Referenced from: /usr/local/bin/curl
  Reason: image not found
/Users/johannes/.pyenv/plugins/python-build/bin/python-build: line 368: 53069 
Abort trap: 6           curl -q -o "${2:--}" -sSLf ${CURL_OPTS} "$1"
error: failed to download Python-3.5.7.tar.xz

BUILD FAILED (OS X 10.14.5 using python-build 1.2.13)

The fix was to add

PATH="/usr/local/opt/curl/bin:$PATH"

to my environment.

like image 31
Johannes Maria Frank Avatar answered Sep 27 '22 20:09

Johannes Maria Frank


It solves my problem after reinstalling aria2 with:

brew uninstall aria2' then 'brew install aria2
like image 44
MuMu Avatar answered Sep 27 '22 21:09

MuMu