linux環境下 python環境import找不到自定義的模塊
問題現象:
Linux環境中自定義的模塊swport,import swport 出錯。swport模塊在/root/sw/目錄下。
解決方法1:此種辦法當時生效,但是需要寫入每一個文件中,才能import不出錯。
import sys sys.path.append('/root/sw') import swport #成功
解決方法2:修改環境變量/etc/profile
vi /etc/profile 在最后一行添加
export PYTHONPATH=$PYTHONPATH:/root/sw/
source /etc/profile 立即生效,所有文件都可以引入/root/sw/下的模塊。