Python Linux下執行Python指令碼

2021-10-12 10:35:31 字數 3173 閱讀 2265

linux下執行python指令碼親測可用

1.linux python環境

linux系統一般整合python,如果沒有安裝,可以手動安裝,聯網狀態下可直接安裝。fedora下使用yum install,ubuntu下使用apt-get install,前提都是root許可權。安裝完畢,可將python加入環境變數,這樣在使用python時無須每次都指定安裝路徑。加入環境變數有兩種方法:

方法1:直接在命令終端輸入命令,立即生效,但重啟後失效,如下。

export path="$path:/usr/bin/python"

此處只介紹方法1,親測有效。

2.在伺服器上檢視python環境是否就緒

輸入python -v

[root@izm5e5bb879z home]

# python -v

# installing zipimport hook

import zipimport # builtin

# installed zipimport hook

# /usr/lib64/python2.7/site.pyc matches /usr/lib64/python2.7/site.py

import site # precompiled from /usr/lib64/python2.7/site.pyc

# /usr/lib64/python2.7/os.pyc matches /usr/lib64/python2.7/os.py

import os # precompiled from /usr/lib64/python2.7/os.pyc

import errno # builtin

import posix # builtin

# /usr/lib64/python2.7/posixpath.pyc matches /usr/lib64/python2.7/posixpath.py

import posixpath # precompiled from /usr/lib64/python2.7/posixpath.pyc

# /usr/lib64/python2.7/stat.pyc matches /usr/lib64/python2.7/stat.py

import

stat

# precompiled from /usr/lib64/python2.7/stat.pyc

# /usr/lib64/python2.7/genericpath.pyc matches /usr/lib64/python2.7/genericpath.py

import genericpath # precompiled from /usr/lib64/python2.7/genericpath.pyc

# /usr/lib64/python2.7/warnings.pyc matches /usr/lib64/python2.7/warnings.py

import warnings # precompiled from /usr/lib64/python2.7/warnings.pyc

# /usr/lib64/python2.7/linecache.pyc matches /usr/lib64/python2.7/linecache.py

import linecache # precompiled from /usr/lib64/python2.7/linecache.pyc

# /usr/lib64/python2.7/types.pyc matches /usr/lib64/python2.7/types.py

import types # precompiled from /usr/lib64/python2.7/types.pyc

# /usr/lib64/python2.7/userdict.pyc matches /usr/lib64/python2.7/userdict.py

import userdict # precompiled from /usr/lib64/python2.7/userdict.pyc

# /usr/lib64/python2.7/_abcoll.pyc matches /usr/lib64/python2.7/_abcoll.py

import _abcoll # precompiled from /usr/lib64/python2.7/_abcoll.pyc

# /usr/lib64/python2.7/abc.pyc matches /usr/lib64/python2.7/abc.py

import abc # precompiled from /usr/lib64/python2.7/abc.pyc

# /usr/lib64/python2.7/_weakrefset.pyc matches /usr/lib64/python2.7/_weakrefset.py

import _weakrefset # precompiled from /usr/lib64/python2.7/_weakrefset.pyc

3.新建test.py檔案,裡面簡單寫一句python語句

#!/usr/bin/python

print 「hello codertalk!」

第一行需增加 #!/usr/bin/python制定為python編譯解析

4.修改text.py的許可權

chmod u+x test.py

chmod u+x test.py
5.執行檔案 python test.py

[root@izm5e9wyhcz home]

# python test.py

hello codertalk!

[root@izm5e9wyb879z home]

# python test.py

hello codertalk!

[root@izm5e9wyhc5bb879z home]

# python test.py

hello codertalk!

[root@izm5e9wyh79z home]

# python test.py

hello codertalk!

[root@izm5e9wy879z home]

# python test.py

hello codertalk!

python linux 下開發環境搭建

1.1 在虛擬環境目錄下安裝 ipython pip install ipython 1.2 簡單的使用 ipthyon print heollo,word exit 2.1 安裝 jupyter pip installjupyter 2.2 修改密碼 jupyter notebook passwo...

Python linux下的pip安裝

今天寫的是pip安裝,為啥寫呢,因為發現還是有必要寫的 網上流傳以下幾種安裝 然後執行以下命令 需要管理員許可權 python get pip.py 試了試 不行 然後解壓 tar zxvf 解壓之後會有個資料夾 進入到資料夾,執行命令python setup.py install 安裝完之後執行 ...

python linux下簡單的排序

1 選擇排序 把乙個數與餘下所有的數排序,最小的排到最前面 root besttest liyn test cat test.py usr bin python a 1,3,5,2 for i in range 0,len a 1 定位陣列的第幾個 for j in range i 1 len a ...