How can I compile a python file exclude a certain module?
Let's see a example:
there is def b()
in b.py
called in main.py
, how can I just compile main.py
, because I need to modify def b()
in b.py
afterward. Or can I compile them separately?
I am using pyinstaller
now, but I can change to other compile tools if it can implement this.
Thanks
It's a bad idea to do this: pyinstaller is meant for packaging and distribution, not for development. Packaged file aren't meant to be changed. If part of the program is modified, you should release a new version of the whole package. If you would like to do runtime configuration, then you should use a configuration file, rather than changing the program.
However, if you insist on doing it, you could use the --exclude-module
flag. Run
pyinstaller --exclude-module b main.py
so that b
is not bundled with main. If you try to run the bundled package now, a ModuleNotFoundError: No module named 'b'
would show. Copy b.py
to the directory (dist/main
), run main
, and everything would work again. Now you could change b.py
, and the difference would show during the execution.