I have two directories. Directory named Dir1 has class definitions Directory named Dir2 has the import statement: from Dir1.guitarClass import Guitar, ElectricGuitar, BassGuitar
Both directories have been set as "Mark directory as Namespace package"
I run the program from the Terminal. ---
(venv) xxxxxxxxxx@MacBook-Air eraseme % python "Dir2/knowyourguitar.py"
and receive this error:
Traceback (most recent call last): File "/Users/xxxxxxxx/PycharmProjects/eraseme/Dir2/knowyourguitar.py", line 3, in from Dir1.guitarClass import Guitar, ElectricGuitar, BassGuitar ModuleNotFoundError: No module named 'Dir1'
This is my screen shot of the Pycharm:
You are approaching this issue in the wrong way, this has nothing to do with Pycharm.
Pycharm may have marked it as a namespace package, but that doesn't mean that it is a namespace package.
You may want to create a file named __init__.py
under Dir1
, that's how you make a directory into an importable module.
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.