【Redhat7.0】Linux下python3.6安装

python3.6.5安装
1.在官网中下载源码https://www.python.org/downloads/release/python-365/
2.在Linux中解压:tar -zxvf Python-3.6.5.gz
3.准备编译环境 yum install gcc
4.准备安装依赖包
zlib,openssl。python的pip需要依赖这两个包
yum install zlib* openssl*
5.预编译
./configure --prefix=/usr/python-3.6.5 --enable-optimizations
6.编译(耗时将近半小时,电脑配置低了)
make(整个编译过程不出现error才是没问题的)
7.安装make install
8.配置环境变量:
PATH:
配置的目的:让系统帮我自动找到命令执行文件路径
path值:一堆目录,每个目录之间用:隔开

vim ~/.bashrc 在文件的最后一行新建一行
PATH=$PATH:/usr/python-3.6.5/bin
保存退出

执行命令: source ~/.bashrc,为了加载~/.bashrc。只要~/.bashrc文件被修改就需要source

第二种配置方式:
PYTHONE_HOME=/usr/python-3.6.5
PATH=$PATH:$PYTHONE_HOME/bin

最后安装一个python的工具:ipython
执行命令:pip3 install ipython
注意:
/etc/profile:整个系统的环境变量。
~/.bashrc:当前用户的环境变量。

【已解决】
遇到的问题:

[root@linuxprobe home]# pip3 install ipython
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting ipython
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/ipython/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/ipython/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/ipython/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/ipython/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/ipython/
  Could not fetch URL https://pypi.python.org/simple/ipython/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ipython/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
  Could not find a version that satisfies the requirement ipython (from versions: )
No matching distribution found for ipython

如果碰到了这个,输入

# python3
>>> import ssl

会显示没有这个模块,而在python2中是有的。
原因是pip的依赖包zlib,openssl没安装好或者没有重新编译和安装。

那么按照上述流程重新来一遍。

# yum install zlib* openssl*
# ./configure --prefix=/usr/python-3.6.5 --enable-optimizations
# make 
# make install 

最后再pip3 install ipython
显示如下:

Collecting ipython
  Downloading https://files.pythonhosted.org/packages/b1/7f/91d50f28af3e3a24342561983a7857e399ce24093876e6970b986a0b6677/ipython-6.4.0-py3-none-any.whl (750kB)
    100% |████████████████████████████████| 757kB 101kB/s 
Collecting prompt-toolkit<2.0.0,>=1.0.15 (from ipython)
  Downloading https://files.pythonhosted.org/packages/04/d1/c6616dd03701e7e2073f06d5c3b41b012256e42b72561f16a7bd86dd7b43/prompt_toolkit-1.0.15-py3-none-any.whl (247kB)
    100% |████████████████████████████████| 256kB 49kB/s 
Collecting pexpect; sys_platform != "win32" (from ipython)
  Downloading https://files.pythonhosted.org/packages/b9/3c/e51a76fe78a877afd9acd95a51e3b7610c0983b19ef5a5dfa11735a619b8/pexpect-4.5.0-py2.py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 48kB/s 
Requirement already satisfied: setuptools>=18.5 in /usr/python-3.6.5/lib/python3.6/site-packages (from ipython)
Collecting decorator (from ipython)
  Downloading https://files.pythonhosted.org/packages/bc/bb/a24838832ba35baf52f32ab1a49b906b5f82fb7c76b2f6a7e35e140bac30/decorator-4.3.0-py2.py3-none-any.whl
Collecting backcall (from ipython)
  Downloading https://files.pythonhosted.org/packages/84/71/c8ca4f5bb1e08401b916c68003acf0a0655df935d74d93bf3f3364b310e0/backcall-0.1.0.tar.gz
Collecting pickleshare (from ipython)
  Downloading https://files.pythonhosted.org/packages/9f/17/daa142fc9be6b76f26f24eeeb9a138940671490b91cb5587393f297c8317/pickleshare-0.7.4-py2.py3-none-any.whl
Collecting traitlets>=4.2 (from ipython)
  Downloading https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl (74kB)
    100% |████████████████████████████████| 81kB 93kB/s 
Collecting simplegeneric>0.8 (from ipython)
  Downloading https://files.pythonhosted.org/packages/3d/57/4d9c9e3ae9a255cd4e1106bb57e24056d3d0709fc01b2e3e345898e49d5b/simplegeneric-0.8.1.zip
Collecting pygments (from ipython)
  Downloading https://files.pythonhosted.org/packages/02/ee/b6e02dc6529e82b75bb06823ff7d005b141037cb1416b10c6f00fc419dca/Pygments-2.2.0-py2.py3-none-any.whl (841kB)
    100% |████████████████████████████████| 849kB 54kB/s 
Collecting jedi>=0.10 (from ipython)
  Downloading https://files.pythonhosted.org/packages/e7/42/074192a165622e645ed4aeade63e76e56b3496a044569b3c6cae3a918352/jedi-0.12.0-py2.py3-none-any.whl (172kB)
    100% |████████████████████████████████| 174kB 115kB/s 
Collecting six>=1.9.0 (from prompt-toolkit<2.0.0,>=1.0.15->ipython)
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.15->ipython)
  Downloading https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython)
  Downloading https://files.pythonhosted.org/packages/ff/4e/fa4a73ccfefe2b37d7b6898329e7dbcd1ac846ba3a3b26b294a78a3eb997/ptyprocess-0.5.2-py2.py3-none-any.whl
Collecting ipython-genutils (from traitlets>=4.2->ipython)
  Downloading https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting parso>=0.2.0 (from jedi>=0.10->ipython)
  Downloading https://files.pythonhosted.org/packages/cd/3e/5908f9577dbd1e5df53e64349bfd11e46b726c1e4d8cd676bbe8aa4de316/parso-0.2.1-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 151kB/s 
Installing collected packages: six, wcwidth, prompt-toolkit, ptyprocess, pexpect, decorator, backcall, pickleshare, ipython-genutils, traitlets, simplegeneric, pygments, parso, jedi, ipython
  Running setup.py install for backcall ... done
  Running setup.py install for simplegeneric ... done
Successfully installed backcall-0.1.0 decorator-4.3.0 ipython-6.4.0 ipython-genutils-0.2.0 jedi-0.12.0 parso-0.2.1 pexpect-4.5.0 pickleshare-0.7.4 prompt-toolkit-1.0.15 ptyprocess-0.5.2 pygments-2.2.0 simplegeneric-0.8.1 six-1.11.0 traitlets-4.3.2 wcwidth-0.1.7
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@linuxprobe bin]# pip3 install --upgrade pip

成功!

猜你喜欢

转载自blog.csdn.net/feng_zhiyu/article/details/80467393