程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Resolving Python error modulenotfounderror: no module named xxx‘

編輯:Python

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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved