【记录一次崩溃的linux下安装python3和fastapi】

一、1.安装python3

wget http://npm.taobao.org/mirrors/python/3.7.5/Python-3.7.5.tar.xz
#解压
xz -d Python-3.7.5.tar.xz
tar -xf Python-3.7.5.tar

#进入解压后的目录,依次执行下面命令进行手动编译
cd Python-3.7.5
./configure prefix=/usr/local/python3
#编译结束可以先看下python -V 
#看看这个下面有没有绑定python2
#绑定了,软连接最好写成/usr/bin/python3(可以区分python2和python3)
#添加python3的软链接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3.7/bin/pip3.7 /usr/bin/pip3
#测试是否安装成功了
python3 -V

2.安装python3需要注意的问题

我就是绑定的时候把软连接直接写成了/usr/bin/python,我的python3的软连接直接覆盖python2。(中途yum可用)

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python

找了半天python2又映射回去,刚开始映射的2.7.

ln -s /usr/bin/python2.7 /usr/bin/python

二、安装fastapi第三方库(比较啰嗦)

然后安装fastapi,说openssl不行,版本比较低。
报错

ERROR: Could not find a version that satisfies the requirement fastapi (from versions: none)
ERROR: No matching distribution found for fastapi
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

在这里插入图片描述
开始安装openssl,安装这个需要用yum安装依赖包,

yum install gcc libffi-devel zlib* openssl-devel

发现yum没了,离大谱,明明前面还能用。想着要不要重新安装一下yum,于是,开始下载yum

wget http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz
tar xvf yum-3.2.28.tar.gz
cd yum-3.2.28
yum(查看版本)

还是不成功,报错

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

在这里插入图片描述
然后直接查了一下这个错误,看到一个回答,说可能是python2.7和yum不太匹配,我又换成了python2.6,好了,yum回来了。

回来之后,继续安装openssl,

yum install gcc libffi-devel zlib* openssl-devel

可能会报错

Loaded plugins: fastestmirror, refresh-packagekit, security
You need to be root to perform this command.

在这里插入图片描述
请在前面加上sudo
后续还可能报错,

You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

在这里插入图片描述
请在后面加上–skip-broken
后续报错

Error Summary

在这里插入图片描述
(我自己放弃了,下面是大佬的解决办法,做一下叙述,记录一下)
说是前面的内容和后面的内容冲突了,准确说是yum源下载的和缓存的冲突了。建议查看一下linux系统版本和yum源。
最后是更新yum源就解决问题了。yum源配置文件位置etc/yum/repos.d/CentOS6-Base.repo

三、代替方法linux下安装fastapi(安装Miniconda)

简介:Miniconda是一款小巧的python环境管理工具,安装包大约只有50M多点,其安装程序中包含conda软件包管理器和Python。一旦安装了Miniconda,就可以使用conda命令安装任何其他软件工具包并创建环境等。
安装虚拟环境,配置环境,安装python3和fastapi

#下载miniconda安装包 
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh
#安装
bash Miniconda3-py39_4.9.2-Linux-x86_64.sh
#进入base虚拟环境
bash(遇到问题,普通用户安装失败,root用户可以)

#创建一个名称为python37的环境,python版本等于3.7
conda create -n python37 python=3.7
#激活环境/进入环境
source activate python37 或者conda activate python37
#在环境激活的情况下安装fastapi
conda install fastapi

其他命令或配置

#配置conda镜像如下命令,或者修改.condarc文件(没有就创建)
source ~/.bashrc
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
conda config --set show_channel_urls yes
#查看已有环境
conda info --env
#查看已有安装包
conda list
#退出环境
conda deactivate
#删除某个环境
conda remove -n 环境名 --all
#删除某个环境下的某个包
conda remove -n 环境名 包名
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值