Skip to content Skip to sidebar Skip to footer

Building A Python Wheel : "no Module Named ______"

I am trying to build a python wheel on a complex program, and I have issues with imports. So I managed to reproduce it on a elementary example. The program works fine when directly

Solution 1:

You are getting a ModuleNotFoundError because the interpreter is searching for a global module named tata, and not looking in the current directory. You are also repeating this behavior, in your first code block.

In the following snippet you are running main.py as python path/to/main.py

import subfolder.titi as titi # Does not throw any error

the reason this does not throw any error is because, you are not running main as a package, so when you reference subfolder it checks in your current working directory.

Instead when you try to run setup.py to build, the interpreter will run everything as a package, and thus, will not look in any local directories. You'll have to change your imports like this

# notice the .from .subfolder import titi 
from .tata import tata 

Your file structure looks something like this

-> module (directory)---- main.py---- tata.py----> subfolder (directory)-------- titi.py

to run any of these as a module, instead of using python main.py you'll have to cd 1 step back, into the parent directory of module and use python -m module main.py,and make sure that you are using imports with . to refrence files in the same directory. Normally this is how development of python-pip packages is done, in order to make it easier in the setup.py proccess.

Post a Comment for "Building A Python Wheel : "no Module Named ______""