I know how to import a package or module, but I meet a quite strange problem.
If I run swmm5_extend_function/example.py
, everything is fine. However, when I run example.py
, errors occur:
Traceback (most recent call last):
File "example.py", line 2, in <module>
from swmm5_extend_function.Swmm5Extend import SWMM5ReadInp
File "C:\project\swmm5_extend_function\Swmm5Extend.py", line 1, in <module>
import swig.SWMM5ReadInpFile as swmm
ModuleNotFoundError: No module named 'swig'
Here is my project structure:
project/
-- example.py
-- ......
-- swmm5_extend_function/
-- __init__.py
-- example.py
-- Swmm5Extend.py
-- swig/
-- __init__.py
-- SWMM5ReadInpFile.py
-- ....
Here is code of each .py file:
swmm5_extend_function/Swmm5Extend.py
import swig.SWMM5ReadInpFile as swmm
class SWMM5ReadInp(object):
pass
swmm5_extend_function/example.py
from Swmm5Extend import SWMM5ReadInp
example.py
from swmm5_extend_function.Swmm5Extend import SWMM5ReadInp
I want to know why this strange error happens.
swig/
is in the same folder asswmm5_extend_function/example.py
, but notexample.py
. – MisterMiyagi Feb 11 at 14:13import swig.SWMM5ReadInpFile as swmm
toimport swmm5_extend_function.swig.SWMM5ReadInpFile as swmm
– rukh-ta Feb 11 at 14:14/project/
folder. If that's the case, you're calling 2 differentexample.py
files. – Gsk Feb 11 at 14:39