ubuntu升级python3.7.6(含make test报错“Tests result: FAILURE then FAILURE”排错)

1.下载python3.7.6

网上给出的以下两种下载方式都已失效

apt-get install python3.7
# 或者
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1rc2.tgz

手动下载
python官方ubuntu python3.7.6

2.安装python3.7.6

tar -zxvf Python-3.7.6.tgz

3. 配置安装位置

./configure	
# 或者
./configure --prefix=/usr/local/python3.7.1		

4.编译、测试

cd Python-3.7.6
make
make test

5.测试结束,报告有错

== Tests result: FAILURE then FAILURE ==

386 tests OK.

2 tests failed:
    test_normalization test_zipfile

28 tests skipped:
    test_bz2 test_ctypes test_curses test_dbm_gnu test_dbm_ndbm
    test_devpoll test_gzip test_idle test_kqueue test_lzma test_msilib
    test_ossaudiodev test_readline test_smtpnet test_sqlite test_ssl
    test_startfile test_tcl test_tix test_tk test_ttk_guionly
    test_ttk_textonly test_turtle test_winconsoleio test_winreg
    test_winsound test_zipfile64 test_zlib

2 re-run tests:
    test_normalization test_zipfile

Total duration: 13 min 34 sec
Tests result: FAILURE then FAILURE
Makefile:1085: recipe for target 'test' failed
make: *** [test] Error 2

6.排错,安装缺少的模块

sudo apt-get update
sudo apt-get upgrade
apt-get install -y zlib*
apt-get install --reinstall zlibc zlib1g zlib1g-dev
apt-get install libffi-dev libssl-dev libreadline-dev -y
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

重新编译、测试

#重复操作
cd Python-3.7.6

./configure
#或者
./configure --prefix=/usr/local/python3.7.1	

make
make test

测试结果:success

== Tests result: SUCCESS ==

402 tests OK.

14 tests skipped:
    test_bz2 test_devpoll test_kqueue test_lzma test_msilib
    test_ossaudiodev test_startfile test_tix test_tk test_ttk_guionly
    test_winconsoleio test_winreg test_winsound test_zipfile64

Total duration: 9 min 26 sec
Tests result: SUCCESS

7.安装

make install

安装success

Looking in links: /tmp/tmp0n2_qpu3
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0

若 ./configure,
则安装后可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/include,其它的资源文件放在/usr /local/share。

若./configure --prefix=/usr/local/python3.7.1,
则可执行文件放在/usr /local/python3.7.1/bin,库文件放在/usr/local/python3.7.1/lib,配置文件放在/usr/local/python3.7.1/include,其它的资源文件放在/usr /local/python3.7.1/share

8.配置环境变量

若./configure --prefix=/usr/local/python3.7.1,则需要添加环境变量。
若./configure的无需配置

# 添加环境变量
PATH=$PATH:$HOME/bin:/usr/local/python3.7.1/bin
# 查看环境变量
echo $PATH

9.更改默认指向python3.7

由于python3.7是自己安装的,不在/usr/bin下,而在usr/local/bin或者/usr/local/python3.7.1/bin下(取决于前面执行的./configure还是./configure --prefix=/usr/local/python3.7.1。因此需要先加一条软链接并且把之前的python命令改为python.bak,同时pip也需要更改。依次执行以下命令

若python3.7安装时,执行的是./configure,则:

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python3 /usr/bin/python
mv /usr/bin/pip /usr/bin/pip.bak
ln -s /usr/local/bin/pip3 /usr/bin/pip

若python3.7安装时,执行的是./configure --prefix=/usr/local/python3.7.1,则为:

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/python3.7.1/bin/python3.7 /usr/bin/python
mv /usr/bin/pip /usr/bin/pip.bak
ln -s /usr/local/python3.7.1/bin/pip3 /usr/bin/pip

10.python验证成功

ubuntu升级python3.7.6(含make test报错“Tests result: FAILURE then FAILURE”排错)_第1张图片

你可能感兴趣的:(知识点,linux,python,ubuntu,pip)