编译安装python需要哪些依赖

2025-04-04 19:24:03
推荐回答(1个)
回答1:

依赖库:

//使用apt 安装即可
1.gcc, make, zlib1g-dev(压缩/解压缩库)
安装过程需要的库。
2.libbz2-dev
bz2支持库,若在编译安装python前没有安装,将无法通过pip install 安装提供bz2格式的第三方库,会出现unsupported archive format: .tar.bz2的错误,例如爬虫库Scrapy依赖的Twisted。
3.libsqlite3-dev
sqlite3支持库,若在编译安装python前没有安装,则python中会缺失sqlite3模块,当引入sqlite3或使用依赖sqllite3的第三方库(例如Scrapy)时,会出现ImportError: No modul named _sqllite3的错误。
//以上为编译安装前需要安装的库,可能不够全面,会不断补充。
4.其他:安装第三方库需要的库
python3-dev, libxml2-dev, libxslt1, libffi-dev, libssl-dev等,在安装第三方库会有具体说明,不做过多解释。

安装:

//通过wget获取压缩包,这里选择3.6.1版
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
//解压
tar xJf Python-3.6.1.tar.xz
cd Python-3.6.1
./configure
make
/*这步如果需要sudo,请使用sudo -H命令,即sudo -H make install,避免pip等模块安装失败。
错误示例(pip安装失败):The directory '/home/ls/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
*/
make install