Python3、setuptools、Pip3安裝詳解
博客核心內容:
1、Python3安裝
2、setuptools安裝
3、Pip3安裝
- 1
- 2
- 3
之所以寫這篇博客,也是有很多原因了,每次安裝都要從網上各種百度,網上的答案也是各種各樣,於是決定好好總結一下,下面是我在安裝的過程中參考的幾篇博客,附上相應的鏈接:
http://www.cnblogs.com/rookie404/p/6142151.html
http://www.cnblogs.com/wenchengxiaopenyou/p/5709218.html
https://seofangfa.com/python-note/setuptools-compression-requires-the-missing-zlib-module.html
http://daiqingyang.blog.51cto.com/1070509/1275432/
好的,接下來進入文章的正題:
linux下安裝python3
不建議卸載python2 可能會導致系統內其他軟件無法使用.
1、下載
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0a1.tar.xz
2、解壓
tar xvf Python-3.6.0a1.tar.xz
3、編譯安裝
進入目錄Python-3.6.0a1,執行以下兩個命令:
./configure
make && make install
4、測試
輸入python3:
[root@iz2zea81ksgk8xh72ofrr0z tmp]# python3 Python 3.6.0a1 (default, Aug 19 2017, 14:53:46) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
- 1
- 2
- 3
- 4
- 5
如果顯示上面的內容,說明安裝成功。
部分截圖:
接下來我們來安裝setuptools,到這里面遇到了開始遇到坑了。
1、下載
wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
2、解壓
tar -zxvf setuptools-19.6.tar.gz
[root@iz2zea81ksgk8xh72ofrr0z software]# ll |grep setuptools-19.6 drwxr-xr-x 10 501 games 4096 Aug 19 17:34 setuptools-19.6 -rw-r--r-- 1 root root 641502 Jan 25 2016 setuptools-19.6.tar.gz
- 1
- 2
- 3
3、進入setuptools-19.6編譯安裝
cd setuptools-19.6.tar.gz python3 setup.py build python3 setup.py install
- 1
- 2
- 3
- 4
- 5
到這里如果你還沒有報錯的話,說明setuptools已經安裝成功了,但是在這里我遇到了一個坑,當我執行python3 setup.py install時出現了錯誤,報錯信息如下:
Compression requires the (missing) zlib module.
- 1
出錯原因:提示的很清楚,缺少 zlib模塊導致安裝失敗
處理方式:
1、先安裝缺少的模塊(2行命令)
yum install zlib
yum install zlib-devel
2、下載zlib成功后, cd Python-3.6.0a1的目錄,重新執行下面的這個命令:
make && make install
- 1
3、重新進入setuptools-19.6目錄,再次執行下面的命令:
python3 setup.py install
- 1
到這里問題解決,setuptools-19.6安裝成功.
接下來我們安裝Pip3
1、下載
wget –no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
2、解壓
tar -zxvf pip-8.0.2.tar.gz
[root@iz2zea81ksgk8xh72ofrr0z software]# ll |grep pip drwxr-xr-x 7 501 games 4096 Aug 19 17:44 pip-8.0.2 -rw-r--r-- 1 root root 1130183 Aug 19 17:40 pip-8.0.2.tar.gz
- 1
- 2
- 3
3、進入pip-8.0.2目錄,編譯安裝:
cd pip-8.0.2 python3 setup.py build python3 setup.py install
- 1
- 2
- 3
- 4
- 5
到這里pip3就安裝成功了,可以檢查一下:
[root@iz2zea81ksgk8xh72ofrr0z software]# whereis pip3 pip3: /usr/local/bin/pip3 /usr/local/bin/pip3.6
- 1
- 2
我當時到這里以為安裝成功了,但是當執行pip3的時候,報錯了,信息如下:
cannot import name HTTPSHandler.
- 1
問題:提示的很清楚,缺少 HTTPSHandler模塊導致安裝失敗
處理方式:
1、先安裝缺少的模塊(2行命令)
yum install openssl yum install openssl-devel
- 1
- 2
2、下載 HTTPSHandler成功后, cd Python-3.6.0a1的目錄,重新執行下面的這個命令:
make && make install
- 1
當我執行完上一行命令之后,出現了下面的日志(部分)
Ignoring indexes: https://pypi.python.org/simple Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Found existing installation: setuptools 19.6 Uninstalling setuptools-19.6: Successfully uninstalled setuptools-19.6 Found existing installation: pip 8.0.2 Uninstalling pip-8.0.2: Successfully uninstalled pip-8.0.2 Successfully installed pip setuptools
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
從最后一行Successfully installed pip setuptools可以看出,我的setuptools和pip隨之跟着也成功了,驗證一下:
[root@iz2zea81ksgk8xh72ofrr0z software]# pip3
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion
help Show help for commands.
General Options:
-h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log <path> Path to a verbose appending log. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to alternate CA bundle. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
OK,大功告成!
總結一下注意的點,每次安裝完缺少的模塊之后,都需要:cd Python-3.6.0a1的目錄,重新執行下面的這個命令:
make && make install