Linux install python3.6, pip3 and lower numpy

Linux installation python3.6.8, pip3 and lower numpy

This article is based on ubuntu system environment, installation and use python3.6 and pip3

  • Ubuntu 14.04
  • python 3.6.8

(1) Installation python3.6.8

  • 3.6.8 official website to download Python
    Python-3.6.8.tgz
  • Go to the download directory, decompress
tar -xzvf Python-3.6.8.tgz
# 可能会出现解压错误,那么执行下面代码
gzip -d Python-3.6.8.tgz
tar -xvf Python-3.6.8.tar
  • Into the extracted directory
cd Python-3.6.8
  • Set the installation path and install
./configure --prefix=/usr/local/python3.6 --enable-shared
make
sudo make install
# 在make install的时候可能会出现ZipImportError异常,
# 此时可以考虑在一台相同系统的机器下利用sudo apt-get install zlib1g-dev 解决,
# 然后将生成的包python3.6拷贝至此电脑中
# 检查/usr/bin/目录下是否有链接 python3,如果有则删除
sudo rm -r /usr/bin/python3
# 如果没有则,执行下面的命令
sudo ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
sudo cp -R /usr/local/python3.6/lib/* /usr/lib
  • Python 3.6.8 to check whether the installation was successful
python3 -V

(2) Installation pip

  • In python 3.6.8 comes with a pip, so only need to create a link on the line
sudo ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip
  • Pip check whether the installation was successful
pip -V

(3) third-party packages installed numpy

Use pip install numpy

sudo pip install numpy

Offline installation numpy

pip install numpy-1.16.4-cp36-cp36m-manylinux1_x86_64.whl
  • Go to the official website to download the installation package .tgz file numpy
# ".tar.gz"文件解压
tar -xzvf numpy-1.15.0.tar.gz 
# 进入目录"numpy-1.15.0"
cd numpy-1.15.0
# 找到“setup.py”文件,然后安装
python3 setup.py install

(4) Installation unusual problem

  • ZipImportError abnormal
# 如果在make install的时候出现下面的错误
# zipimport.ZipImportError: can't decompress data; zlib not available
# Makefile:1079: recipe for target 'install' failed
# make: *** [install] Error 1
# 那么,执行下面的命令,并且重新 make & make install
sudo apt-get install zlib1g-dev
make
sudo make install
  • ModuleNotFoundError abnormal
# 如果在sudo pip install numpy的时候出现下面的错误
# File"/usr/local/lib/python3.6/subprocess.py", line 418,in run 
# output=stdout, stderr=stderr)subprocess.CalledProcessError:
# Command'('lsb_release', '-a')'returned non-zeroexitstatus 1.
# 解决思路:
# 找到lsb_release.py文件和CommandNotFound目录,把它们拷贝到报的错误中
# subprocess.py所在文件夹
sudo find / -name 'lsb_release.py'
# result:
# /usr/share/pyshared/lsb_release.py
# /usr/lib/python2.7/dist-packages/lsb_release.py
# /usr/lib/python3/dist-packages/lsb_release.py
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3.6/lib/python3.6/


Published 68 original articles · 98 won praise · views 1.01 million +

Guess you like

Origin blog.csdn.net/qq_32599479/article/details/90648385