indygreg / indygreg/PyOxidizer
ModuleNotFoundError: How to configure my project so the primary module with a main function is found?
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 256
- PR merge metrics
- No merged PRs in 30d
Description
My goal is to build a single file executable that I can distribute to users so they don't need to worry about installing Python or anything else in order to run my code.
I have built my first project with PyOxidizer but when I attempt to run it (initial testing on the same system where it was built) I get a `ModuleNotFoundError`.
The project's repository structure looks like this (some non-consequential files have been ommitted for brevity):
```
myproj # top-level of the repository
|
+-- myproj # primary module of the project
|
+-- __init__.py
+-- __main__.py
+-- submodule1.py
+-- submodule2.py
+-- pyembed # added by PyOxidizer
+-- src # added by PyOxidizer
+-- license.txt
+-- pyoxidizer.toml
+-- README.md
+-- requirements.txt
+-- setup.py
```
The file `myproj.__main__.py` contains a `main` function where most of the action happens, and with that function are calls to a few of the functions defined within the submodule files. The `myproj.__main__.py` file looks like this:
```
def main():
# lots of code here
if __name__ == "__main__":
main()
```
Below are the uncommented parts of the `pyoxidizer.toml` file:
```
[[build]]
application_name = "deep_monitor"
[[embedded_python_config]]
raw_allocator = "jemalloc"
[[embedded_python_config]]
build_target = "x86_64-pc-windows-msvc"
raw_allocator = "system"
[[packaging_rule]]
type = "stdlib-extensions-policy"
policy = "all"
[[packaging_rule]]
type = "stdlib"
include_source = false
[[packaging_rule]]
type = "write-license-files"
path = ""
[[packaging_rule]]
type = "package-root"
path = "myproj"
packages = ["myproj"]
[[embedded_python_run]]
mode = "module"
module = "myproj.__main__"
```
I have built the project apparently without error, but when I run it I see this:
```
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'myproj'
```
BTW I get the same error if I instead use the following `embedded _python_run` setting within the `pyoxidizer.toml` file:
```
mode = "eval"
code = "from myproj.__main__ import main; main()"
```
Can anyone advise as to how I can overcome this issue, and/or if I should be doing things in a different manner? Maybe I need to somehow install the `myproj` module into the Python environment?
Thanks in advance for any suggestions or assistance. And thanks also to the creator and contributors on this project, it looks like it will be quite useful once I work out how to use it correctly.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with pyoxidizer.toml, especially the package-root packaging rule and embedded_python_run entries, then reproduce the build and executable launch described in the issue. Done means the generated executable can import myproj.__main__ and invoke its main function without ModuleNotFoundError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100