精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Centos7下完美安裝部署python3.10

jf_TEuU2tls ? 來源:浩道linux ? 2023-07-29 16:15 ? 次閱讀

前段時間浩道分享了一篇關(guān)于pycharm專業(yè)版本安裝破解后,不少小伙伴后臺咨詢浩道,linux環(huán)境下如何安裝更高版本的python3,畢竟系統(tǒng)默認(rèn)自帶的python2版本已經(jīng)不符合當(dāng)前發(fā)展潮流,本文浩道就centos7下安裝部署python3.10.9版本帶大家通過以下15個步驟完成,其它版本安裝都可以參照如下步驟進行。福利在文末喔~

步驟1、首先使用 python -V 命令查看一下是否安裝Python,如下所示:

[root@huanghao-1 ~]# python -V
Python 2.7.5

由上面命令可以知道,CentOS7默認(rèn)安裝了python2.7.5 ,因為一些命令要用它,比如yum 它使用的是python2.7.5。

步驟2、然后使用命令 which python 查看一下Python可執(zhí)行文件的位置,可見執(zhí)行文件在/usr/bin/ 目錄下。如下所示:

[root@huanghao-1 ~]# which python
/usr/bin/python

步驟3、通過cd /usr/bin/命令切換到/usr/bin/目錄下執(zhí)行ll python* 命令查看,如下所示 :

[root@huanghao-1 bin]# cd /usr/bin/
[root@huanghao-1 bin]# ll python*
lrwxrwxrwx. 1 root root    7 Jul 28  2018 python -> python2
lrwxrwxrwx. 1 root root    9 Jul 28  2018 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Nov 20  2015 python2.7

由上面可知,python 指向的是python2.7,今天我們安裝3.10版本,所以python要指向python3.10才行。

步驟4:通過cd /usr/bin/切換到/usr/bin/目錄下,執(zhí)行mv python python.bak命令進行備份。若有過程中用到y(tǒng)um,可以暫時恢復(fù)回來?。。?/span>,執(zhí)行ll python* 命令查看,如下所示:

[root@huanghao-1 bin]# cd /usr/bin/
[root@huanghao-1 bin]# mv python python.bak
[root@huanghao-1 bin]# ll python*          
lrwxrwxrwx. 1 root root    9 Jul 28  2018 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Nov 20  2015 python2.7
lrwxrwxrwx. 1 root root    7 Jul 28  2018 python.bak -> python2

步驟5、通過yum命令先安裝相關(guān)包:

yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

[root@huanghao-1 bin]# yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

執(zhí)行以上命令后,可以報錯了,不要慌!!這是因為我們在步驟4中改變了其環(huán)境變量,在/usr/bin目錄下,通過命令mv python.bak python還原回來即可再次執(zhí)行安裝命令就正常了但是安裝完后記得備份回去!??!

mv python python.bak

步驟6、下載python3.10.9的源碼,自己創(chuàng)建一個目錄保存源碼,我自己放在/home/目錄下。通過cd /home/命令切換到/home/目錄下,執(zhí)行wget下載命令:

wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tar.xz

如果自己系統(tǒng)沒有wget命令,則yum安裝一下。

yum install-y wget

自己想安裝什么python3版本,就到https://www.python.org/getit/這個網(wǎng)站找,只需將以上版本路徑替換即可。

(1)如我這里安裝python3.10.9,打開上面網(wǎng)址后如下圖所示:

b74f1d74-2db8-11ee-815d-dac502259ad0.png

(2)選擇對應(yīng)python版本后,點擊“download”后,下拉找到file頁面,如下圖所示:

b77e4e6e-2db8-11ee-815d-dac502259ad0.png

(3)此時復(fù)制鏈接地址后,即可通過wget + 鏈接地址進行python源碼下載,如下命令所示,這里對應(yīng)步驟6的命令:

wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tar.xz

步驟7、在/home/目錄下已經(jīng)看到下載好的源碼,通過tar -xvJf Python-3.7.0a4.tar.xz命令進行解壓縮。如下所示:

[root@huanghao-1 home]# ll
total 19156
-rw-r--r-- 1 root root 19612112 Dec  7 03:01 Python-3.10.9.tar.xz
[root@huanghao-1 home]# tar -xvJf  Python-3.10.9.tar.xz

步驟8、/home/目錄下,通過命令cd Python-3.10.9切換進入源碼包目錄。

cd Python-3.10.9

步驟9、編譯安裝,依次執(zhí)行以下命令進行:

./configureprefix=/usr/local/python3.10 --with-ssl
make&&makeinstall

等待安裝完畢后,通過命令cd/usr/local/切換到/usr/local/目錄下,通過ll命令查看,就會有python3.10目錄了,如下圖所示:

[root@huanghao-1 Python-3.10.9]# cd /usr/local/
[root@huanghao-1 local]# ll
total 0
drwxr-xr-x. 2 root root  6 Aug 12  2015 bin
drwxr-xr-x. 2 root root  6 Aug 12  2015 etc
drwxr-xr-x. 2 root root  6 Aug 12  2015 games
drwxr-xr-x. 2 root root  6 Aug 12  2015 include
drwxr-xr-x. 2 root root  6 Aug 12  2015 lib
drwxr-xr-x. 2 root root  6 Aug 12  2015 lib64
drwxr-xr-x. 2 root root  6 Aug 12  2015 libexec
drwxr-xr-x  6 root root 52 Mar 26 19:06 python3.10
drwxr-xr-x. 2 root root  6 Aug 12  2015 sbin
drwxr-xr-x. 5 root root 46 Jul 28  2018 share
drwxr-xr-x. 2 root root  6 Aug 12  2015 src
[root@huanghao-1 local]#

步驟10、將python3.10版本對應(yīng)的執(zhí)行文件添加軟鏈接到執(zhí)行目錄下/usr/bin,通過以下命令完成:

ln-s/usr/local/python3.10/bin/python3.10/usr/bin/python

最終結(jié)果如下所示:

[root@huanghao-1 bin]# cd /usr/bin/
[root@huanghao-1 bin]# ll python*  
lrwxrwxrwx  1 root root   36 Mar 26 19:11 python -> /usr/local/python3.10/bin/python3.10
lrwxrwxrwx. 1 root root    9 Jul 28  2018 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 Nov 20  2015 python2.7
lrwxrwxrwx. 1 root root    7 Jul 28  2018 python.bak -> python2

步驟11、測試是否成功安裝,執(zhí)行python -V命令,執(zhí)行python2 -V,輸出如下所示:成功安裝python3.10.9版本。

[root@huanghao-1 bin]# python -V
Python 3.10.9
[root@huanghao-1 bin]# python2 -V
Python 2.7.5

步驟12、因為執(zhí)行yum等命令需要python2版本,所以我們還要修改yum配置及其它相關(guān)配置:

(1)執(zhí)行命令vi /usr/bin/yum進行修改,修改內(nèi)容如下:

把#! /usr/bin/python修改為:

#! /usr/bin/python2

(2)執(zhí)行命令vi /usr/libexec/urlgrabber-ext-down

把文件里面的#! /usr/bin/python 也要修改為:

#! /usr/bin/python2

(3)執(zhí)行命令vi /usr/sbin/firewalld

文件里面的#!/usr/bin/python -Es也要修改為:

#!/usr/bin/python2 -Es

步驟13、建立pip3的軟鏈接,執(zhí)行以下命令:

ln -s /usr/local/python3.10/bin/pip3 /usr/bin/pip3

步驟14、這樣python3版本就安裝完成,同時python2也存在:可以通過以下命令進行查看:

[root@huanghao-1 bin]# python -V
Python 3.10.9
[root@huanghao-1 bin]# python2 -V
Python 2.7.5

步驟15、此時發(fā)現(xiàn)安裝完成后,無法通過pip3命令安裝相關(guān)模塊,如:

[root@huanghao-1 ~]#pip3installFlask
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: 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/flask/
WARNING: 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/flask/
WARNING: 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/flask/
WARNING: 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/flask/
WARNING: 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/flask/
Could not fetch URL https://pypi.org/simple/flask/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/flask/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement Flask (from versions: none)
ERROR: No matching distribution found for Flask
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: There was an error checking the latest version of pip.
[root@node1 Python-3.10.9]# pip3 install --upgrade pip
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Requirement already satisfied: pip in /usr/local/python3.10/lib/python3.10/site-packages (22.3.1)
WARNING: 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/pip/
WARNING: 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/pip/
WARNING: 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/pip/
WARNING: 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/pip/
WARNING: 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/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: There was an error checking the latest version of pip.

如上出現(xiàn)報錯,此時可以按照如下方法進行解決。

(1)在用戶家目錄下創(chuàng)建相關(guān)文件后進行如下編輯:

[root@huanghao-1 ~]# mkdir -p ~/.pip
[root@huanghao-1 ~]# vi ~/.pip/pip.conf

(2)在上一步編輯文件中,新增如下內(nèi)容:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple


[install]
trusted-host = mirrors.aliyun.com

(3)此時再次安裝相應(yīng)模塊,如下可以成功了。

[root@huanghao-1 ~]# pip3 install Flask
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting Flask
  Downloading http://mirrors.aliyun.com/pypi/packages/fa/1a/f191d32818e5cd985bdd3f47a6e4f525e2db1ce5e8150045ca0c31813686/Flask-2.3.2-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.9/96.9 kB 1.8 MB/s eta 000
Collecting Jinja2>=3.1.2
  Downloading http://mirrors.aliyun.com/pypi/packages/bc/c3/f068337a370801f372f2f8f6bad74a5c140f6fda3d9de154052708dd3c65/Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 1.4 MB/s eta 000
Collecting click>=8.1.3
  Downloading http://mirrors.aliyun.com/pypi/packages/1a/70/e63223f8116931d365993d4a6b7ef653a4d920b41d03de7c59499962821f/click-8.1.6-py3-none-any.whl (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 1.4 MB/s eta 000
Collecting Werkzeug>=2.3.3
  Downloading http://mirrors.aliyun.com/pypi/packages/ba/d6/8040faecaba2feb84e1647af174b3243c9b90c163c7ea407820839931efe/Werkzeug-2.3.6-py3-none-any.whl (242 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 242.5/242.5 kB 1.5 MB/s eta 000
Collecting blinker>=1.6.2
  Downloading http://mirrors.aliyun.com/pypi/packages/0d/f1/5f39e771cd730d347539bb74c6d496737b9d5f0a53bc9fdbf3e170f1ee48/blinker-1.6.2-py3-none-any.whl (13 kB)
Collecting itsdangerous>=2.1.2
  Downloading http://mirrors.aliyun.com/pypi/packages/68/5f/447e04e828f47465eeab35b5d408b7ebaaaee207f48b7136c5a7267a30ae/itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting MarkupSafe>=2.0
  Downloading http://mirrors.aliyun.com/pypi/packages/12/b3/d9ed2c0971e1435b8a62354b18d3060b66c8cb1d368399ec0b9baa7c0ee5/MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, itsdangerous, click, blinker, Werkzeug, Jinja2, Flask
Successfully installed Flask-2.3.2 Jinja2-3.1.2 MarkupSafe-2.1.3 Werkzeug-2.3.6 blinker-1.6.2 click-8.1.6 itsdangerous-2.1.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv


[notice] A new release of pip available: 22.3.1 -> 23.2.1
[notice] To update, run: /usr/local/python3.10/bin/python3.10 -m pip install --upgrade pip

(4)根據(jù)提示,也可以升級pip版本到最新的版本。

pip3 install --upgrade pip

(5)下面可以通過創(chuàng)建一段腳本,驗證下載的模塊是否可以正常使用,創(chuàng)建名為hello_flask.py的文件,內(nèi)容如下:

[root@huanghao-1 ~]# cat hello_flask.py 
from flask import Flask


app = Flask(__name__)


@app.route('/')
def hello():
        return 'Hello flask'


if __name__ == '__main__':
app.run(host='0.0.0.0',port=8888,debug=True)

(6)執(zhí)行hello_flask.py腳本

python hello_flask.py

(7)當(dāng)前我的服務(wù)器地址是192.168.20.232,在瀏覽器訪問如下地址:得到響應(yīng)如下圖所示:

b7b3b824-2db8-11ee-815d-dac502259ad0.png

到此整個安裝部署完成,大家可以參考以上步驟自己進行各個python3版本的安裝,注意更改到自己實際環(huán)境中的對應(yīng)目錄即可。

PS:學(xué)習(xí)python,怎么能少了專業(yè)版的開發(fā)工具pycharm呢!需要專業(yè)破解版可以看看之前發(fā)布的這篇文章,三部完美破解,有效期到2099年!

【python開發(fā)工具】pycharm專業(yè)版安裝破解激活


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • Linux
    +關(guān)注

    關(guān)注

    87

    文章

    11123

    瀏覽量

    207919
  • python
    +關(guān)注

    關(guān)注

    53

    文章

    4753

    瀏覽量

    84081

原文標(biāo)題:【文末送書】Centos7下完美安裝部署python3.10

文章出處:【微信號:浩道linux,微信公眾號:浩道linux】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦

    CentOS7配置Tomcat的安裝和整合Jenkins

    第七章----CentOS7 配置 Tomcat 整合Jenkins自動部署
    發(fā)表于 03-29 11:53

    centos7 redis的安裝

    centos7 redis 使用,查看Redis工具(安裝、添加權(quán)限驗證、添加開機自啟)
    發(fā)表于 05-14 17:13

    安裝linux lnmp centos7環(huán)境的小問題總結(jié)

    最近在安裝linuxlnmp centos7環(huán)境的時候還是有點小問題,從頭總結(jié)了一
    發(fā)表于 07-22 07:09

    基于CentOS7的MySQL57安裝

    MySQL57在CentOS7上的安裝配置
    發(fā)表于 03-26 08:45

    VMware虛擬機安裝CentOS7教程步驟

    超詳細(xì)的VMware虛擬機安裝CentOS7教程
    發(fā)表于 05-27 11:25

    Centos7如何使用Apache部署Django項目

    Centos7使用Apache部署Django項目
    發(fā)表于 05-29 12:26

    Centos7Nginx安裝與配置步驟

    Centos7 Nginx安裝與配置,防火墻開啟端口監(jiān)聽
    發(fā)表于 06-02 12:58

    請問Centos7如何搭建PPTP?

    搭建清單:Centos7 (我這里使用騰訊云的服務(wù)器)ppp和pptpd 包iptables (我這里使用iptables)win10客戶端(連接測試使用)
    發(fā)表于 11-09 07:54

    為什么VMware安裝CentOS7剛開啟虛擬機時就出現(xiàn)黑屏呢

    為什么VMware安裝CentOS7剛開啟虛擬機時就出現(xiàn)黑屏呢?是什么原因呢?有何解決辦法?
    發(fā)表于 10-26 06:25

    安裝centos7之掛在分區(qū)的方法

    1、安裝centos7之掛在分區(qū)的方法:在安裝過程中,進行分區(qū)操作時,首先選擇“自動配置分區(qū)”(Automatiaclly configure partitioning),在這里將準(zhǔn)備好的ext3
    發(fā)表于 12-27 08:05

    CentOS7如何設(shè)置電源選項/待機/睡眠/掛起

    設(shè)置裝有 CentOS7 的筆記本合蓋后黑屏進入睡眠模式 systemd 能夠處理某些電源相關(guān)的 ACPI事件,你可以通過從 /etc/systemd/logind.conf 以下選項進行配置
    發(fā)表于 12-28 07:28

    在vmware上安裝centos7以及網(wǎng)絡(luò)配置

    啃論文之余,想自己搭個虛擬機玩玩。vmware10;centos7 X86_64. 1. 在vmware上安裝centos7 1.1去官網(wǎng)上下載DVD centos7的iso鏡像,大約
    發(fā)表于 12-02 15:41 ?531次閱讀

    CentOS7 設(shè)置電源選項,待機、睡眠、掛起

    設(shè)置裝有 CentOS7 的筆記本合蓋后黑屏進入睡眠模式 systemd 能夠處理某些電源相關(guān)的 ACPI事件,你可以通過從 /etc/systemd/logind.conf 以下選項進行配置
    發(fā)表于 01-05 15:10 ?1次下載
    <b class='flag-5'>CentOS7</b> 設(shè)置電源選項,待機、睡眠、掛起

    CentOS7中使用一鍵腳本部署Librenms網(wǎng)絡(luò)監(jiān)控系統(tǒng)

    今天在CentOS7使用一鍵腳本部署Librenms網(wǎng)絡(luò)監(jiān)控系統(tǒng)。
    的頭像 發(fā)表于 09-14 09:27 ?934次閱讀
    <b class='flag-5'>CentOS7</b>中使用一鍵腳本<b class='flag-5'>部署</b>Librenms網(wǎng)絡(luò)監(jiān)控系統(tǒng)

    記錄RocketMQ在centos7上的安裝過程

    本文記錄RocketMQ在centos7上的安裝過程,沒有技術(shù)的探討,僅僅是安裝記錄,以作備忘。
    的頭像 發(fā)表于 01-02 11:41 ?1012次閱讀
    記錄RocketMQ在<b class='flag-5'>centos7</b>上的<b class='flag-5'>安裝</b>過程