Ubuntu 在不影響系統自帶python的情況下安裝多個python3虛擬環境
阿新 • • 發佈:2020-10-28
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