问题
I want to compile a Python 3.3 module with submodules using cx_freeze.
So, my dir strucuture is:
projectname/
__init__.py
submodule1/
__init__.py
bootstrap.py
script1.py
submodule11/
script2.py
submodule2/
...
In the __init__.py
I import
from submodule1 import bootstrap
and from the bootstrap
import submodule1.submodule11.script2
If I run the init file, anything is good and the script with the submodule imports is executed correctly.
When I compile it, I use this setup.py:
from cx_Freeze import setup,Executable
import sys
includes = []
excludes = ['Tkinter']
packages = ['submodule1', 'submodule2']
base = "Win32GUI"
setup(
name = 'myapp',version = '0.1',description = 'app',author = 'user',
options = {'build_exe': {'excludes':excludes,'packages':packages}},
executables = [Executable('__init__.py',base=base)]
)
and run the script in the 'projectname' dir.
But if I start the application I get ImportError: no module named 'submodule1.submodule11'
from an error dialog.
And it's true: in the library.zip this submodule doens't exist.
What do I do wrong?
回答1:
So, I found the answer: every module MUST have a __init__.py
file in it's folder so python would know that it's a package, not just some folder. Now I compile my project.
来源:https://stackoverflow.com/questions/25938252/cx-freeze-and-importing-modules