Problem description : In the Linux environment, an error occurred when importing the custom module swport. The swport module is in the /root/sw/ directory.
Solution 1 : This method took effect at the time, but it needs to be written into each file in order to import without error.
import sys
sys.path.append('/root/sw')
import swport
Solution 2 : Modify the environment variable /etc/profile
vi /etc/profile Add in the last line
export PYTHONPATH=$PYTHONPATH:/root/sw/
source /etc/profile takes effect immediately, and all files can be imported into modules under /root/sw/.
Original link: https://www.cnblogs.com/sitongyan/p/10641863.html