Skip to content Skip to sidebar Skip to footer

Imports Custom Module Python

I have a file I.py and X.py both are custom modules I'm trying to do an import from X.py file like: from myapp.I import Int But, when I try to run in shell, it throws an import er

Solution 1:

You're going to need an __init__.py within myapp/ and myapp/a/. See What is __init__.py for? for more details.

Solution 2:

You can't execute X.py directly, even with the required __init__.py files (have you added those?)

This is a limitation (or feature, depending on how you see it). To get around it, you need to create a simple runner script of sorts in the top-level directory which then imports X and executes it.

Post a Comment for "Imports Custom Module Python"