ubuntu 18.04 安装 python 3.7 及 安装python三方库 遇到的问题和解决思路

本文详细介绍如何在Linux环境下配置Python3.7仓库,安装虚拟环境venv,以及解决安装过程中可能遇到的错误,如'bdist_wheel'无效命令和Python.h文件缺失等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# 配置仓库
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa

# 这里是安装 python3.7.5 之后, 需要安装三方库和包的情况, 解决安装 venv 不成功的问题:
sudo apt install python3.7 python3-venv python3.7-venv
python3.7 -m venv my_env_name

# 如果虚拟环境中安装三方库还会报其他错, 如:
# 1.报错: error: invalid command 'bdist_wheel'
# 解决:
pip install wheel

另外一个报错的解决:
`
  creating build/temp.linux-x86_64-3.7/MySQLdb
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 -I/usr/include/mysql -I/home/guang/Desktop/WorkSpace/sp-biz/sp-env/include -I/usr/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.7/MySQLdb/_mysql.o
  MySQLdb/_mysql.c:37:10: fatal error: Python.h: No such file or directory
   #include "Python.h"
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for mysqlclient
`
# 解决思路
sudo apt-get install python3.7-dev default-libmysqlclient-dev
回答: 在Ubuntu 18.04系统中安装Python 3.7可以按照以下步骤进行操作。首先,需要执行系统升级来确保系统是最新的版本。可以使用以下命令执行升级: sudo apt update sudo apt upgrade -y 接下来需要安装编译Python源程序所需的包。可以使用以下命令安装这些包: sudo apt install build-essential -y sudo apt install libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev -y sudo apt-get install zlib1g-dev 然后,需要下载Python 3.7的源程序压缩包。可以使用wget命令下载: wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz 接着,需要解压缩下载的压缩包。可以使用以下命令进行解压缩: tar -xzvf Python-3.7.1.tgz 然后进入解压缩后的目录,并进行配置: cd Python-3.7.1 ./configure --enable-optimizations 配置完成后,可以使用make命令编译并安装Python 3.7: make sudo make install 最后,可以将python3指向Python 3.7版本。可以使用以下命令进行设置: sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.7 1 这样,Python 3.7安装完成了,并且python3命令将指向Python 3.7版本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ubuntu18.04安装python3.7并将python3指向python3.7](https://blog.csdn.net/yiyu3344/article/details/90102410)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [【PythonUbuntu 18.04 安装 python3.7](https://blog.csdn.net/qq_35933777/article/details/84325856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值