Centos上安裝python3.5以上版本

1、準備工做:

  yum install zlib-develhtml

  yum install openssl-develpython

2、安裝python3.5

  wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgzpython2.7

  tar -zxvf Python-3.5.3.tgz測試

  cd Python-3.5.3fetch

  ./configure --prefix=/usr/local/python3 --enable-sharedui

  make && make installthis

3、替換系統中的python

  mv /usr/bin/python  python.bakurl

  ln -s /usr/local/python3.5/bin/python3 /usr/bin/pythonspa

  因爲更改系統默認的python會影響yum,需修改以下兩個文件:code

  /usr/bin/yum和/usr/libexec/urlgrabber-ext-down

 1 Known problems with Fedora Linux and Python 3 version: Error message:
 2 # yum search package
 3   File "/usr/bin/yum", line 30
 4     except KeyboardInterrupt, e:
 5                             ^
 6 SyntaxError: invalid syntax
 7 If you set python3 globally on your system change the yumshebang to python2:
 8 # vi /usr/bin/yum
 9 FROM:
10 #!/usr/bin/python
11 TO:
12 #!/usr/bin/python2.7
13 Similarly: Error message:
14 Downloading packages:
15   File "/usr/libexec/urlgrabber-ext-down", line 28
16     except OSError, e:
17                   ^
18 SyntaxError: invalid syntax
19 Exiting on user cancel
20 The issue is also related to Python 3 set as a default global version. To fix this error update/usr/libexec/urlgrabber-ext-down script:
21 # vi /usr/libexec/urlgrabber-ext-down
22 FROM:
23 #!/usr/bin/python
24 TO:
25 #!/usr/bin/python2.7

4、安裝setuptools

  wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

  tar -zxvf setuptools-19.6.tar.gz

  cd setuptools-19.6

  python3 setup.py build

  python3 setup.py install

  (若有報錯: RuntimeError: Compression requires the (missing) zlib module,則須要安裝yum install zlib-devel,安裝後要從新編譯 python3.5:  

make && make install)

5、安裝pip

  wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

  tar -zxvf pip-8.0.2.tar.gz

  cd pip-8.0.2

  python3 setup.py build

  python3 setup.py install

  使用pip安裝包測試:

    如報錯,則缺乏yum install openssl-devel,安裝完成後同樣須要從新編譯python3.5(make&&make install)

[root@localhost pip-9.0.1]# python -m pip install paramiko
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting paramiko
  Could not fetch URL https://pypi.python.org/simple/paramiko/: 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 paramiko (from versions: ) No matching distribution found for paramiko

  

  參考:

    http://www.tuicool.com/articles/j2ueiir

    http://www.cnblogs.com/Yemilice/p/6217250.html

相關文章
相關標籤/搜索