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

 

相关文章:

  • 2021-07-16
  • 2021-12-04
  • 2022-12-23
  • 2021-12-23
  • 2021-10-10
  • 2021-07-11
  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-12-06
  • 2021-07-27
相关资源
相似解决方案