新聞中心
在Ubuntu系統(tǒng)中運(yùn)行Python,首先需要確保已經(jīng)安裝了Python,如果沒(méi)有安裝,可以通過(guò)以下步驟進(jìn)行安裝:

創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)公司是一家服務(wù)多年做網(wǎng)站建設(shè)策劃設(shè)計(jì)制作的公司,為廣大用戶提供了網(wǎng)站制作、做網(wǎng)站,成都網(wǎng)站設(shè)計(jì),廣告投放平臺(tái),成都做網(wǎng)站選創(chuàng)新互聯(lián)建站,貼合企業(yè)需求,高性價(jià)比,滿足客戶不同層次的需求一站式服務(wù)歡迎致電。
1、打開(kāi)終端(快捷鍵:Ctrl+Alt+T)。
2、更新軟件包列表:
sudo aptget update
3、安裝Python3:
sudo aptget install python3
4、安裝完成后,可以通過(guò)以下命令查看Python版本:
python3 version
接下來(lái),我們將學(xué)習(xí)如何在Ubuntu系統(tǒng)中運(yùn)行Python程序。
方法一:直接運(yùn)行Python文件
1、打開(kāi)終端。
2、使用cd命令切換到包含Python文件的目錄,
cd /home/yourusername/yourfolder
3、使用以下命令運(yùn)行Python文件(將yourfile.py替換為實(shí)際的文件名):
python3 yourfile.py
方法二:使用Python解釋器交互式運(yùn)行代碼
1、打開(kāi)終端。
2、輸入python3或python,然后按回車(chē)鍵啟動(dòng)Python解釋器,這將顯示Python提示符(>>>)。
3、在提示符下輸入Python代碼,然后按回車(chē)鍵執(zhí)行。
>>> print("Hello, World!")
4、要退出Python解釋器,請(qǐng)輸入exit(),然后按回車(chē)鍵。
方法三:使用IDLE運(yùn)行Python程序
1、打開(kāi)終端。
2、輸入以下命令啟動(dòng)IDLE(Python自帶的集成開(kāi)發(fā)環(huán)境):
idle3
或者
idle
注意:如果你的系統(tǒng)中沒(méi)有IDLE,可以使用以下命令安裝:
sudo aptget install idle3
或者
sudo aptget install idle
3、IDLE啟動(dòng)后,會(huì)出現(xiàn)一個(gè)窗口,在窗口中,可以創(chuàng)建新的Python文件、打開(kāi)現(xiàn)有的Python文件以及運(yùn)行Python程序,點(diǎn)擊菜單欄的“File”>“New File”可以創(chuàng)建新的Python文件;點(diǎn)擊菜單欄的“File”>“Open”可以打開(kāi)現(xiàn)有的Python文件;點(diǎn)擊菜單欄的“Run”>“Run Module”可以運(yùn)行當(dāng)前打開(kāi)的Python文件。
方法四:使用Jupyter Notebook運(yùn)行Python程序
1、打開(kāi)終端。
2、輸入以下命令安裝Jupyter Notebook(如果尚未安裝):
pip3 install jupyter notebook
或者(推薦):
pip install jupyter notebook upgrade user
3、安裝完成后,輸入以下命令啟動(dòng)Jupyter Notebook(將yourusername替換為你的實(shí)際用戶名):
jupyter notebook generateconfig user yourusername notebookdir=/home/yourusername/yourfolder/ ip='*' port=8888 nobrowser allowroot NotebookApp.token='' NotebookApp.password='' NotebookApp.base_url=http://localhost:8888/tree/ # (NotebookApp.token='' and NotebookApp.password='' are optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional) & disown %1 & wait %1 > /dev/null 2>&1 & sleep 5s && open http://localhost:8888/tree/ # (optional)& disown %2096744974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974974# exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear; exit; clear
名稱(chēng)欄目:ubuntu如何運(yùn)行python
分享網(wǎng)址:http://www.dlmjj.cn/article/copijoe.html


咨詢
建站咨詢
