简体   繁体   中英

Python package not seeing module in same directory

My project structure is like this:

Project
│   main.py
│
└───dataPacks
    │   hwPack.py
    │   swPack.py
    │   __init__.py   

in dataPacks/__init__.py I'm trying to import swPack.py with the line import swPack for use as a Package module but it doesn't seem to see it. I am getting the error No module named 'swPack'

Why can't it see the module?

您必须使用以下代码,因为 dunder init 用于初始化所有其他模块,因此如果您在init .py 中,则必须使用以下代码才能导入 swPack.py:

import dataPacks.swPack
from Project.dataPacks import swPack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM