Neither 'pyenv' nor 'asdf' could be found to install Python

发布时间: 2020-12-20 10:33:52 作者: 大象笔记

背景

系统环境

但是,这个 Python 项目在 pipenv 配置文件中指定的 python 版本是 3.8。

所以,执行 pipenv shell 命令时,报错:

$ pipenv shell

Warning: Python 3.8 was not found on your system...
Neither 'pyenv' nor 'asdf' could be found to install Python.
You can specify specific versions of Python with:
$ pipenv --python path/to/python

pyenv 是用来管理多版本 Python 的一个工具。

安装 pyenv

参考 https://github.com/pyenv/pyenv

例如我是 Ubuntu 18.04 + Fish shell

> git clone https://github.com/pyenv/pyenv.git ~/.pyenv
> set -Ux PYENV_ROOT $HOME/.pyenv
> set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths

至此,安装并配置成功 pyenv。

自动安装指定的 Python 版本

再次执行

> pipenv shell

Warning: Python 3.8 was not found on your system...
Would you like us to install CPython 3.8.6 with Pyenv? [Y/n]: Y
Installing CPython 3.8.6 with /home/zhongwei/.pyenv/bin/pyenv (this may take a few minutes)...

会看到 pipenv 调用 pyenv 自动安装缺失的 Python 版本。

但是,pyenv 下载太慢了

由于 pyenv 默认从国外服务器下载,下载过程漫长,而且没有进度提示。无法忍受,可以直接从国内镜像下载对应 python 版本到 pyenv 的 cache 目录,然后手动安装。

$ version="3.8.6"; echo $version; wget "https://mirrors.huaweicloud.com/python/$version/Python-$version.tar.xz" -P ~/.pyenv/cache/;pyenv install $version

报错 zipimport.ZipImportError: can't decompress data; zlib not available

sudo apt-get install zlib1g-dev

参考

我是一名山东烟台的开发者,联系作者