The prompt is that the customized package cannot be found , In fact, there are ,__init__.py There are also documents ( Under the bag, if there is no __init__.py Just create one ).
After investigation , Is the path incorrect , terms of settlement :
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
It's easy to use , such as A The file introduces B,B Is in a file larger than A Two floors high , Then nested os.path.dirname two , Nesting several layers is just a few os.path.dirname
For example, the author's situation is as follows :
root directory
----A
-------a.py
----B
-------C
-----------c.py
in other words c.py Introduced in a.py Correct the mistakes reported by others , Now c.py Is nested three levels os.path.dirname.
And sys.path.append This sentence must be put in the wrong place import That's on the line Fang , Otherwise, it will be in vain .