MedicineMan
MedicineMan

Reputation: 15314

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)

Upvotes: 8

Views: 4498

Answers (5)

Agnel
Agnel

Reputation: 31

For my case set the environment variable PYTHON_BUILD_HTTP_CLIENT solved the issue.

export PYTHON_BUILD_HTTP_CLIENT=curl

Upvotes: 3

Han He
Han He

Reputation: 3461

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

Upvotes: 14

MuMu
MuMu

Reputation: 11

It solves my problem after reinstalling aria2 with:

brew uninstall aria2' then 'brew install aria2

Upvotes: 1

Johannes Maria Frank
Johannes Maria Frank

Reputation: 2827

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.

Upvotes: 4

rob123
rob123

Reputation: 493

appears to have been a network error for me - switched to a faster network after confirming file was still available and it installed without problems

Upvotes: -1

Related Questions