python3.7 导入自定义模块报错:ModuleNotFoundError: No module named 'helper'

1、报错:ModuleNotFoundError: No module named 'helper'

打印出 sys.path和site.getsitepackages

# -*- coding:utf8 -*-

import sys
import site
import mockevent.event2 as event2

if __name__ == '__main__':
    event2.flow_12(event2.Bi_316)
    print(sys.path)
    print(site.getsitepackages)

打印结果:

sys.path中项目工程路径,如:

['/Users/xx/Documents/IProject/ne/dutils/ATT', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/xx/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/redis-3.3.8-py3.7.egg', '/Users/xx/Documents/IBTProject/neneus/didi-utils', '/Users/xx/Documents/IBTProject/neneus/didi-utils/mockevent']

 

2、需要在/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages文件夹下创建.pth文件,如:pycharm.pth,导入自定义工程路径

vim pycharm.pth

# 将 pycharmproject 项目的绝对路径写入到文件中

/Users/xx/Documents/IProject/ne/dutils

/Users/xx/Documents/IProject/ne/dutils/mockevent/ATT

 

3、导入自定义类和方法,正常运行

 

可以参考其他同学的解决方法:

方法一:https://blog.csdn.net/cityzenoldwang/article/details/78701990

方法二:https://www.jianshu.com/p/6692b48c7295

 

 

你可能感兴趣的:(python3.7 导入自定义模块报错:ModuleNotFoundError: No module named 'helper')