linux环境下 python环境import找不到自定义的模块

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/下的模块。

猜你喜欢

转载自www.cnblogs.com/sitongyan/p/10641863.html