我在 Ubuntu 上安装 Python 时遇到了一些困难。我不太明白这个错误是什么意思。任何帮助都将不胜感激!
以下是我采取的步骤:
1:安装Pyenv:
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo export PATH="/home/adam/.pyenv/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
echo eval "$(pyenv init -)" >> ~/.bashrc
echo eval "$(pyenv virtualenv-init -)" >> ~/.bashrc
source ~/.bashrc
2:安装Python:
pyenv install --list
pyenv install 3.7.3 <----------- This is where I run into errors.
python --version
这是我收到的错误:
Downloading Python-3.7.3.tar.xz...
-> https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
Installing Python-3.7.3...
BUILD FAILED (Ubuntu 19.04 using python-build 20180424)
Inspect or clean up the working tree at /tmp/python-build.20190429142402.20957
Results logged to /tmp/python-build.20190429142402.20957.log
Last 10 log lines:
File "/tmp/python-build.20190429142402.20957/Python-3.7.3/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/tmp/python-build.20190429142402.20957/Python-3.7.3/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/tmp/python-build.20190429142402.20957/Python-3.7.3/Lib/ensurepip/__init__.py", line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/tmp/python-build.20190429142402.20957/Python-3.7.3/Lib/ensurepip/__init__.py", line 27, in _run_pip
import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [Makefile:1130: install] Error 1
编辑:它已经安装了?我想我的困惑是我测试了它是否已经安装:
python –version
但我把它改成了这样,现在它似乎可以正常工作了:
python3 --version
谢谢你!
答案1
您的 Ubuntu 发行版(似乎是 19.04)附带了 Python 3。因此运行起来python3 --version
“开箱即用”。看来 OP 对 pyenv 的用途有点困惑,pyenv 的用途是轻松在多个 Python 版本之间切换。
以下是我认为有用的链接:
https://realpython.com/intro-to-pyenv/#why-not-use-system-python
https://github.com/pyenv/pyenv/blob/master/README.md
这个问题可能是重复的: https://stackoverflow.com/questions/37227854/pyenv-build-failed-ubuntu-15-04-using-python-build-20160509
我在 Xubuntu 18.04 上使用 pyenv 安装版本 3.8.0 时遇到了类似的问题。按照 nicolas.fg 的回答为我解决了这个问题:
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
答案2
你可以使用 Ubuntu apt 包管理器安装 python
sudo apt python3
如果你尝试安装特定版本的 Python,你可能需要考虑从源代码下载并构建它
你收到的错误是因为你的机器上没有安装 zlib,你可以使用以下命令安装它
sudo apt install zlib1g