ubuntu 22.04 LTS
python3.10
版本太高,需要python3.6,python3.8版本
根据需求,切换,保证原有的系统正常使用;
以,python3.8为例:
1 Ubuntu安装Python3.8
一、安装Python3.8
Ubuntu 官方 apt 库中还未收录 python 3.8,这里使用 deadsnakes PPA 软件源安装。
1、安装依赖包
bash
$ sudo apt-get update
$ sudo apt-get install software-properties-common
2、添加 deadsnakes PPA 源
bash
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
3、安装 python 3.8
bash
$ sudo apt-get install python3.8
2 启动虚拟环境
bash
$ virtualenv -p /usr/bin/python3.8 PY38 --python=python3.8
created virtual environment CPython3.8.17.final.0-64 in 335ms
creator CPython3Posix(dest=/home/book/code/aaa/PY38, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/book/.local/share/virtualenv)
added seed packages: pip==22.0.2, setuptools==59.6.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
3 启动Pip3报错
bash
from distutils.cmd import Command as DistutilsCommand
解决方法:
bash
$ sudo apt-get install python3.8-distutils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
python3.8-lib2to3
The following NEW packages will be installed:
python3.8-distutils python3.8-lib2to3
0 upgraded, 2 newly installed, 0 to remove and 296 not upgraded.
Need to get 319 kB of archives.
After this operation, 1,237 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy/main amd64 python3.8-lib2to3 all 3.8.17-1+jammy1 [126 kB]
Get:2 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy/main amd64 python3.8-distutils all 3.8.17-1+jammy1 [193 kB]
Fetched 319 kB in 11s (28.9 kB/s)
Selecting previously unselected package python3.8-lib2to3.
(Reading database ... 212247 files and directories currently installed.)
Preparing to unpack .../python3.8-lib2to3_3.8.17-1+jammy1_all.deb ...
Unpacking python3.8-lib2to3 (3.8.17-1+jammy1) ...
Selecting previously unselected package python3.8-distutils.
Preparing to unpack .../python3.8-distutils_3.8.17-1+jammy1_all.deb ...
Unpacking python3.8-distutils (3.8.17-1+jammy1) ...
Setting up python3.8-lib2to3 (3.8.17-1+jammy1) ...
Setting up python3.8-distutils (3.8.17-1+jammy1) ...
$pip install -r src/requirements.txt