Ubuntu 在不影响系统自带python的情况下安装多个python3虚拟环境

1. Ubuntu自带python环境的路径通常为/usr/bin /usr/local/bin等,为不形象系统自带的python,新建并将python安装到其它路径,如:/home/myPython/python3.7 

2. 去官网查找自己想要的python版本 https://www.python.org/ftp/python/

比如想安装python3.7.9,执行:wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz

3.下载比较慢,这时候可以再打开一个tab,安装依赖(如果不安装可能在装好python3.7后安装某些库时报缺少_ctypes,据说是因为没有装libffi-dev)

sudo apt update
sudo apt install -y build-essential python-dev python-setuptools python-pip python-smbus
sudo apt install -y libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev
sudo apt install -y zlib1g-dev libc6-dev libsqlite3-dev tk-dev sudo apt install -y libssl-dev openssl libffi-dev

4.解压:tar -xzvf Python-3.7.9.tgz

5.编译:

cd Python-3.7.9
./configure --prefix=/home/myPython/python3.7 --enable-optimizations
make && make install

6. 安装虚拟环境

/home/myPython/python3.7/bin/pip3.7 install virtualenv
cd /opt/pyenv  # 进入想要安装的虚拟环境的路径
/home/myPython/python3.7/bin/virtualenv venv3.7

 

posted @ 2020-10-28 18:01  aaron_agu  阅读(772)  评论(0编辑  收藏  举报