Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic imports don't work if the python path is a level up from their location #12

Closed
ingrinder opened this issue Apr 19, 2020 · 2 comments

Comments

@ingrinder
Copy link

Given a directory structure like this:

project_folder/
└── my_module/
    ├── some_submodules/
    │   ├── module_a.py
    │   └── module_b.py
    └── main.py

If I use absolute imports in my code (e.g. import my_module.some_submodules.module_a), then my $PYTHONPATH must be project_folder, so I execute stickytape in this folder and --add-python-path .

However, if instead of importing the submodules directly in main.py, and instead import using importlib.import_module...

from importlib import import_module
import_module('my_module.some_submodules.module_a.py')

...when I run the stickytape script, I get a traceback ending in ModuleNotFoundError: No module named 'my_module'.

Obviously this is a simplified example but it demonstrates the behaviour I'm getting in some software where modules are dynamically imported with importlib in this way. Perhaps it could be possible to add these submodules to stickytape somehow, like how you can specify hidden modules in PyInstaller?

@mwilliamson
Copy link
Owner

master now has an option --add-python-module in the CLI to explicitly include Python modules. So, in your example, you'd include --add-python-module my_module.some_submodules.module_a. Does that work for you?

@ingrinder
Copy link
Author

Yep, that works perfectly. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants