项目场景:
环境为linux20.04 不习惯使用conda
为了解决多版本兼容问题,打算使用pyenv
下载pyenv
pyenv安装到~/.pyenv
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
然后添加环境 vim ~/.bashrc
export PATH=~/.pyenv/bin:$PATH
export PYENV_ROOT=~/.pyenv
eval "$(pyenv init -)"
更新 source ~/.bashrc
问题出现:
在安装 python3.7时报错
ModuleNotFoundError: No module named '_bz2' 等几个包找不到
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib
刚开始以为是环境配置啥的,后来发现是没安装依赖。
解决方案:
ubuntu 系统
sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev curl \ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
之后就是傻瓜换源安装
v=3.7.0;wget https://npm.taobao.org/mirrors/python/$v/Python-$v.tar.xz -P ~/.pyenv/cache/;pyenv install $v
最后附上官方使用指令Some useful pyenv commands are:
commands List all available pyenv commands
exec Run an executable with the selected Python version
global Set or show the global Python version(s)
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
latest Print the latest installed or known version with the given prefix
local Set or show the local application-specific Python version(s)
prefix Display prefixes for Python versions
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall Python versions
--version Display the version of pyenv
version Show the current Python version(s) and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
whence List all Python versions that contain the given executable
which Display the full path to an executable