rhel7安裝python3
-
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz 下載
-
tar -zxvf Python-3.5.1.tgz 解壓
-
cd Python-3.5.1
./configure
make && make install 進入python目錄,安裝
-
安裝過程中出現不能編譯的情況 ,提示:no acceptable C compiler found in $PATH
提示沒有編譯器環境,安裝gcc就可以了:yum install gcc -y
-
安裝完成,輸入python,出現的是python2.7,這是因為RHEL自帶python2.7,輸入python3就可以了
-
使用過程中,出現方向鍵和刪除鍵亂碼的情況 ,這是因為預設只安裝了readline模組而沒有安裝readline-devel模組,所以只要安裝下即可:yum install readline-devel,安裝後再重新安裝下python3. 使用正常
yum install python36
轉載
(一)簡述
剛安裝的centos7.4版本預設是安裝Python2.7,由於一些命令需要使用的原因,比如yum等,使用的是2.7.5版本的,由於現在很多庫包括django都是使用Python3,
因此,有這樣的需求:yum使用python2.7版本,django和其他的使用預設的python3版本。
(二)檢視並備份python2相關資訊
1,使用python -V 可以檢視預設的版本資訊。
[root@localhost ~]# python -VPython 2.7.5
2,然後使用which python 檢視下python的可執行檔案的位置。
[root@localhost ~]# which python/usr/bin/python
3,可執行檔案在/usr/bin/目錄下,檢視有關python的檔案,ll /usr/bin/python*。通過檢視可以得知python預設指向的是python2.7
[root@localhost ~]# ll /usr/bin/python*lrwxrwxrwx. 1 root root 7 Dec 21 15:23 /usr/bin/python -> python2 lrwxrwxrwx. 1 root root 9 Dec 21 15:23 /usr/bin/python2 -> python2.7-rwxr-xr-x. 1 root root 7136 Aug 4 2017 /usr/bin/python2.7
重要:通過檢視可以得知python預設指向的是python2.7,由於還沒有安裝python3,可以先備份python檔案,等python3安裝好了後再建立軟連線即可
4,備份預設python2.7版本
[root@localhost bin]# mv /usr/bin/python /usr/bin/python.bak
(三)方法一:安裝配置python3
1,安裝相關的包yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
[root@localhost bin]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc makeLoaded plugins: fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 Loading mirror speeds from cached hostfile Package zlib-devel-1.2.7-17.el7.x86_64 already installed and latest version Package 1:openssl-devel-1.0.2k-8.el7.x86_64 already installed and latest version Package ncurses-devel-5.9-14.20130511.el7_4.x86_64 already installed and latest version Package sqlite-devel-3.7.17-8.el7.x86_64 already installed and latest version Package gcc-4.8.5-16.el7_4.1.x86_64 already installed and latest version Package 1:make-3.82-23.el7.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package bzip2-devel.x86_64 0:1.0.6-13.el7 will be installed
2,去python官網下載穩定版(https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz)
[root@localhost usr]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz--2018-03-08 00:05:54-- https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz Resolving www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:12::223Connecting to www.python.org (www.python.org)|151.101.228.223|:443... connected. HTTP request sent, awaiting response... 200 OKLength: 16992824 (16M) [application/octet-stream] Saving to: ‘Python-3.6.4.tar.xz’16% [==============> ] 2,781,624 49.4KB/s eta 4m 49s
3,安裝python3
[root@localhost tmp]# tar xf Python-3.6.1.tar.xz[root@localhost tmp]# cd Python-3.6.1[root@localhost Python-3.6.1]# ./configure prefix=/usr/local/python3[root@localhost Python-3.6.1]# make &&make install
4,在/usr/bin/下建立軟連線
[root@localhost Python-3.6.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python[root@localhost Python-3.6.1]# python -VPython 3.6.1[root@localhost Python-3.6.1]# python2 -VPython 2.7.5[root@localhost Python-3.6.1]# ll /usr/bin/python*lrwxrwxrwx 1 root root 32 Mar 7 05:38 /usr/bin/python -> /usr/local/python3.6/bin/python3 lrwxrwxrwx. 1 root root 9 Jan 29 16:34 /usr/bin/python2 -> python2.7-rwxr-xr-x. 1 root root 7136 Aug 4 2017 /usr/bin/python2.7lrwxrwxrwx. 1 root root 7 Jan 29 16:34 /usr/bin/python2.bak -> python2
5,配置正常使用yum,使yum使用python2.7版本,否則會報錯的。
5.1,修改/usr/bin/yum檔案把#! /usr/bin/python修改為#! /usr/bin/python2
[root@localhost Python-3.6.1]# vim /usr/bin/yum #!/usr/bin/python2
5.2,修改/usr/libexec/urlgrabber-ext-down檔案,把裡面的#! /usr/bin/python 也要修改為#! /usr/bin/python2
[root@localhost Python-3.6.1]# vim /usr/libexec/urlgrabber-ext-down #! /usr/bin/python2
6,如果使用pip的話,簡歷pip3的軟連線。
[root@localhost Python-3.6.1]#ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3[root@localhost Python-3.6.1]# ll /usr/bin/pip3lrwxrwxrwx 1 root root 29 Mar 7 05:41 /usr/bin/pip3 -> /usr/local/python3.6/bin/pip3
至此,一臺伺服器上預設的版本是python3 ,同時python2頁存在了,可以正常使用yum來進行安裝所需的軟體了。
安裝 setuptools
命令:
yum install python-setuptools
完成之後,就可以使用 easy_install 命令安裝 django
easy_install django
相關文章
- RHEL7相關--安裝/命令
- rhel7 安裝11g rac
- RHEL7原始碼安裝Apache服務原始碼Apache
- brew 安裝python3:如何使用brew安裝Python3Python
- RHEL7安裝本地離線yum源倉庫
- mac安裝python3MacPython
- Mac 安裝Python3MacPython
- CentOS 安裝Python3CentOSPython
- CentOS 安裝 Python3CentOSPython
- centOS安裝python3CentOSPython
- linux安裝python3(原始碼安裝)LinuxPython原始碼
- 為CentOS安裝python3CentOSPython
- Linux安裝Python3LinuxPython
- python3安裝scrapy框架Python框架
- Python3安裝requests庫Python
- Python3 安裝Opencv方法PythonOpenCV
- python3環境安裝Python
- 部署虛擬機器環境安裝RHEL7系統虛擬機
- 怎麼解除安裝python3Python
- python3環境如何安裝Python
- mac上如何安裝python3MacPython
- windows10 安裝python3WindowsPython
- linux下安裝python3LinuxPython
- python3安裝和使用virtualenvPython
- Linux下Python3安裝LinuxPython
- 如何在MacOS下安裝Python3MacPython
- python3如何安裝bs4Python
- Win10 安裝 Python3 (上)Win10Python
- CentOS7快速安裝python3CentOSPython
- VirtualBox CentOS 7安裝Python3CentOSPython
- CentOS探索之路3—安裝python3CentOSPython
- CentOS下編譯安裝Python3教程CentOS編譯Python
- CentOS 7 如何編碼安裝Python3?CentOSPython
- centos7編譯安裝python3CentOS編譯Python
- CentOS 7下編譯安裝Python3CentOS編譯Python
- python3安裝scrapy並執行成功Python
- Python3爬蟲利器之ChromeDriver的安裝Python爬蟲Chrome
- Python3爬蟲利器:Appium的安裝Python爬蟲APP