Ubuntu18.04安装pyenv

Table of Contents

安装依赖

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler -y

sudo apt-get install bzip2 -y
sudo apt-get install libbz2-dev -y
sudo apt-get install libbz2-dev -y
sudo apt-get install libssl-dev -y
sudo apt-get install libreadline-dev -y
sudo apt-get install libsqlite3-dev -y

使用自动脚本安装

curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

添加用户环境变量

echo 'export PATH="~/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
exec bash

更新pyenv

~/.pyenv/bin/pyenv update

安装python版本,这里装的是python 3.9.12

mkdir -p ~/.pyenv/cache
wget -c -O ~/.pyenv/cache/Python-3.9.12.tar.xz \
https://repo.huaweicloud.com/python/3.9.12/Python-3.9.12.tar.xz
~/.pyenv/bin/pyenv install -v -f 3.9.12
~/.pyenv/bin/pyenv rehash

设置系统python版本

~/.pyenv/bin/pyenv global 3.9.12
exec bash

更换pip源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install --upgrade pip

安装常用的软件包(如果需要)

pip install requests mysqlpy paramiko ipython numpy scipy opencv-python open3d sanic sanic_cors