Ubuntu 如何安装python3.7.5
首先官网下载 python3.7.5
第一步:进入下载的目录,提取文件
tar -zxvf Python-3.7.5.tgz # 也就是文件名字,按tab即可
提取完文件后进入文件:
cd Python-3.7.5 # 直接输入完P按tab
第二步
然后去文件进入带该对应的文件夹下找到一个 Modules的文件,里面有一个setup文件。
找到这几行,之前是注释的,取消调注释:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/lib/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
上面的SSL要换成自己本地SSL的位置, 可通过:
命令:whereis ssl
输出:ssl: /usr/lib/ssl /etc/ssl /usr/share/man/man7/ssl.7ssl.gz
把第一个位置填入到上面那个SSL=位置。即可
保存退出。
第三步
接下来安装ssl依赖包,输入命令:
sudo apt-get install libssl-dev build-essential libidn11-dev libidn11
第四步
接下来解析python:
./configure --prefix=/文档/python3.7 #(这里选择python3.7的安装位置)
执行完这个指令之后一定要看最后倒数十几行的结果是不是这样子的:
checking if the dirent structure of a d_type field... yes
checking for the Linux getrandom() syscall... yes
checking for the getrandom() function... yes
checking for pkg-config... /usr/bin/pkg-config
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for --with-ssl-default-suites... python
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
config.status: pyconfig.h is unchanged
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
最重要的一段是:
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for --with-ssl-default-suites... python
这才能保证pip之后能和SSL链接上。
第五步
最后开始编译:
sudo make && make install
最后编译完成不能出现 SSL链接失败的英文
第六步
建立软链接
首先查看目前的python指令和pip指令
ls -al /usr/bin | grep python
lrwxrwxrwx 1 root root 23 11月 27 2020 pdb3.8 -> ../lib/python3.8/pdb.py
lrwxrwxrwx 1 root root 19 11月 26 23:02 pip3.7 -> /python3.7/bin/pip3
lrwxrwxrwx 1 root root 31 11月 27 2020 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root root 24 11月 26 23:01 python -> /python3.7/bin/python3.7
lrwxrwxrwx 1 root root 9 11月 27 2020 python3 -> python3.8
-rwxr-xr-x 1 root root 5266168 9月 25 17:36 python3.8
lrwxrwxrwx 1 root root 33 9月 25 17:36 python3.8-config -> x86_64-linux-gnu-python3.8-config
lrwxrwxrwx 1 root root 16 10月 6 18:28 python3-config -> python3.8-config
-rwxr-xr-x 1 root root 384 8月 5 23:56 python3-futurize
-rwxr-xr-x 1 root root 388 8月 5 23:56 python3-pasteurize
-rwxr-xr-x 1 root root 3240 9月 25 17:36 x86_64-linux-gnu-python3.8-config
lrwxrwxrwx 1 root root 33 10月 6 18:28 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.8-config
选择你喜欢的指令名称:
例如python 我这边设置的是python
sudo ln -s 上面你安装python的目录 /usr/bin/你喜欢的指令
例如 sudo ln -s /文档/python3.7/python3.7 usr/bin/python
同样建立pip的软链接
sudo ln -s /文档/python3.7/pip3 usr/bin/pip3.7
如果想要覆盖原先的指令名称建议备份以下:
sudo mv /usr/bin/原先的指令名称 /usr/bin/备份的指令名称
sudo mv /usr/bin/python /usr/bin/python-bat
在使用pip出现
ARNING: The scripts f2py, f2py3 and f2py3.7 are installed in ‘/home/hinleung/.local/bin’ which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
需要添加环境变量:
gedit ~/.bashrc
把下面命令写入到最后一行
export PATH=这里面上面报错的位置信息:$PATH
例如我自己的报错位置信息是:/home/hinleung/.local/bin
export PATH=/home/hinleung/.local/bin:$PATH
保存,然后使其生效:
source ~/.bashrc
问题
一般安装上python后,pip会出现不能通过SSL认证,都是openssl没有和python链接起来。也就是上面第二第三步错了,可以查怎么安装openssl。记住安装的位置
问题
在第五步,编译后出现错误, 没有zlib:
解决方案如下:
https://blog.51cto.com/xxaqustc/1166371
以防上面链接失效,所以我在补充一下, 以下内容为上面链接的原文,此处引用:
输入命令安装即可
$ sudo apt-get install zlib1g
$ sudo apt-get install ruby
$ sudo apt-get install zlib1g-dev
在ubuntu软件源里zlib和zlib-devel叫做zlib1g zlib1g.dev
在ubuntu里,zlib叫zlib1g,相应的zlib-devel叫zlib1g.dev。默认的安装源里没有zlib1g.dev。要在packages.ubuntu.com上找。
适用乌班图系统,centos直接用yum安装zlib即可。
4894



被折叠的 条评论
为什么被折叠?



