安装Python3.6
1. # Centos7默认的 repo有限, 安装epel
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
2. 安装python3.6可能使用的依赖
# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel zlib-devel -y
3. 下载python3.6编译安装
到python官网下载https://www.python.org
下载最新版源码,使用make altinstall,如果使用make install,在系统中将会有两个不同版本的Python在/usr/bin/目录中。这将会导致很多问题,而且不好处理。
# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
# tar -xzvf Python-3.6.4.tgz -C /tmp
# cd /tmp/Python-3.6.4/
把Python3.6安装到/usr/local 目录
# ./configure --prefix=/usr/local/
note: 如遇到 "error: no acceptable C compiler found in $PATH"
[root@localhost Python-3.6.4]# yum install gcc -y
# make
# make altinstall
Note: 如遇错误,请安装依赖包。
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [altinstall] Error 1
[root@localhost Python-3.6.4]# yum install bzip2-devel -y
[root@localhost Python-3.6.4]# yum install zlib-devel -y
[root@localhost Python-3.6.4]# yum install zlib2 -y
[root@localhost Python-3.6.4]# yum install zlib -y
----------------
python3 安装成功,信息如下:
。。。。
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0
------------------------
python3.6程序的执行文件:/usr/local/bin/python3.6
python3.6应用程序目录:/usr/local/lib/python3.6
pip3的执行文件:/usr/local/bin/pip3.6
pyenv3的执行文件:/usr/local/bin/pyenv-3.6
[root@localhost Python-3.6.4]# whereis pip
pip: /usr/local/bin/pip3.6
[root@localhost Python-3.6.4]#
4. 更改/usr/bin/python链接 (默认是Python2.7)
[root@localhost Python-3.6.4]# ls -l /usr/bin/python*
lrwxrwxrwx. 1 root root 7 Jan 20 2018 /usr/bin/python -> python2
lrwxrwxrwx. 1 root root 9 Jan 20 2018 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Aug 3 20:40 /usr/bin/python2.7
# cd /usr/bin
# mv python python.backup
# ln -s /usr/local/bin/python3.6 /usr/bin/python
# ln -s /usr/local/bin/python3.6 /usr/bin/python3
至此,python3已经安装完毕,测试一下:
[root@localhost bin]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python.backup /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.6m /usr/local/bin/python3.6 /usr/local/bin/python3.6m-config /usr/local/lib/python3.6 /usr/include/python2.7 /usr/share/man/man1/python.1.gz
[root@localhost bin]# python
Python 3.6.4 (default, Jan 20 2018, 03:11:08)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
安装virtualenv:
Note: 默认pip是使用Python官方的源,但是由于国外官方源经常被墙,导致不可用,我们可以使用国内的python镜像源,从而解决Python安装不上库的烦恼。
网上有很多可用的源,例如:
豆瓣:http://pypi.douban.com/simple/
清华:https://pypi.tuna.tsinghua.edu.cn/simple
注意后面要有/simple目录!!!
[root@localhost ~]# pip install -i http://pypi.douban.com/simple/ virtualenv
--trusted-host pypi.douban.com
Collecting virtualenv
Downloading http://pypi.doubanio.com/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
| 99% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枆| 1.9MB 8.3MB/s eta 100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.9MB 7.7MB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.0.0
You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@localhost ~]# virtualenv myenv1
Using base prefix '/usr/local'
New python executable in /root/myenv1/bin/python3.6
Also creating executable in /root/myenv1/bin/python
Installing setuptools, pip, wheel...done.
[root@localhost ~]# pwd
/root
[root@localhost ~]# source myenv1/bin/activate
(myenv1) [root@localhost ~]#
Note: 如果在公司访问,使用代理的话:
[root@localhost ~]# export http_proxy="http://1**.2**.33.**:80"
[root@localhost download]# pip install -i http://pypi.douban.com/simple/ virtualenv --trusted-host pypi.douban.com
Collecting virtualenv
Downloading http://pypi.doubanio.com/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1.9MB 56.1MB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.0.0
Important:
1.修改脚本
Centos7下很多脚本是基于python2.7的,安装完python3以后,很多脚本无法正常使用(比如yum), 需要在脚本文件开头更改:
#!/usr/bin/python ===》 #!/usr/bin/python2.7
2.pip3.6 install django
会报错!!
例如这样:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting xxx
Could not fetch URLhttps://pypi.python.org/simple/xxxx/: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement xxx (from versions: )
No matching distribution found for xxx
===》solution:
yum install openssl-devel
重新 make & make install
===> 这表明 要先装python的依赖包,先装python的依赖包,先装python的依赖包,重要事情说3遍! 然后 make & make install 等等
http://blog.csdn.net/a249900679/article/details/51527200 Centos7服务器搭建django项目