以安装python3.7.0为例,其他版本类似
1、依赖
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
注意:安装可能出现ModuleNotFoundError: No module named ‘_ctypes’,因此需安装以下依赖
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
2、源码下载与安装
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
sudo tar xzf Python-3.7.0.tgz
3、编译与安装
cd Python-3.7.0 --
sudo ./configure --enable-optimizations --with-ssl
sudo make altinstall
sudo make altinstall 可用替换:
sudo make
sudo make install
4、链接
若使用python3命令无法调用,使用python3.7
可使用which python3.7查看所在位置,which无法使用时,使用whereis python3.7
cd /python3.7所在目录/
sudo ln -s python3.7 /path/to/python3,即可使用直接使用python3命令
5、其他
离线安装依赖时,在https://pypi.org/ 搜索所需包
xxx.whl的安装:
pip3 install xxx.whl
xxx.tar.gz的安装:
tar -xvf xxx.tar.gz
cd xxx
python3 setup.py install
查看xxx.whl包的必须依赖:
pip3 install pkginfo
pkginfo -f requires_dist xxx.whl
结果输出如下例:
requires_dist: ['pyusb (<1.2.0,>=1.0.0)', 'pyserial (>=3.0)']