File in subpackage not taken into account
Question
I am trying to create an .exe out of my project, but py2exe seem to fail since I added a lib subpackage in which I include external libraries.
Here is how my project is set up :
C:.
¦ LICENSE
¦ README.markdown
¦ requirements.txt
¦ run.sh
¦ setup.py
¦ TODO
¦
+---data
¦ +---input
¦ +---output
+---doc
¦
+---facemovie
¦ ¦ Eye.py
¦ ¦ Face.py
¦ ¦ Facemovie.py
¦ ¦ Facemoviefier.py
¦ ¦ FaceParams.py
¦ ¦ Guy.py
¦ ¦ training_types.py
¦ ¦ __init__.py
¦ ¦
¦ +---lib
¦ exif.py
¦ __init__.py
¦
+---test
context.py
exif_test.py
face_script.py
test_script.py
__init__.py
I do not want to include the test package, neither the doc and data folder into my exe. The root for my executable should be the facemovie package.
I am trying to create the executable through my setup.py file, which is the following :
from distutils.core import setup
import py2exe, sys, os
import facemovie
sys.argv.append('py2exe')
setup(
name = "Facemovie",
url = "https://github.com/jlengrand/FaceMovie",
packages=['facemovie', 'facemovie.lib'],
options = {'py2exe': {'bundle_files': 1, 'includes': ['numpy', 'facemovie.lib.exif'] } },
console=['facemovie/Facemoviefier.py'],
zipfile = None,
)
As you can see, the main entry file of my application is Facemovifier.py. Everything was running fine until I add the lib subpackage.
When I run the py2exe command, here is part of the output :
running install
running build
running build_py
copying facemovie\Eye.py -> build\lib\facemovie
copying facemovie\Face.py -> build\lib\facemovie
copying facemovie\Facemovie.py -> build\lib\facemovie
copying facemovie\Facemoviefier.py -> build\lib\facemovie
copying facemovie\FaceParams.py -> build\lib\facemovie
copying facemovie\Guy.py -> build\lib\facemovie
copying facemovie\training_types.py -> build\lib\facemovie
copying facemovie\__init__.py -> build\lib\facemovie
copying facemovie\lib\exif.py -> build\lib\facemovie\lib
copying facemovie\lib\__init__.py -> build\lib\facemovie\lib
running install_lib
running install_egg_info
Removing C:\Python27\Lib\site-packages\Facemovie-0.4-py2.7.egg-info
Writing C:\Python27\Lib\site-packages\Facemovie-0.4-py2.7.egg-info
running py2exe
.......
Adding python27.dll as resource to C:\Users\jll\perso\workspace\FaceMovie\dist\Facemoviefier.exe
The following modules appear to be missing
['Carbon', 'Carbon.Files', 'Numeric', 'Pyrex.Compiler.Main', '__svn_version__', '_curses', '_scproxy', 'configparser', ..., 'lib.exif']
As you can see, the lib/exif file is actually copied, but not found afterwards.
When I try to run the executable, here is the output :
C:\Users\jll\perso\workspace\FaceMovie\dist>Facemoviefier.
Traceback (most recent call last):
File "Facemoviefier.py", line 12, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "Facemovie.pyc", line 10, in <module>
ImportError: No module named lib.exif
And here is the line of Facemovie.py that causes the error :
import lib.exif as exif
I tried various things and read a lot of docs the last days, but was never able to understand what the problem come from. I have init.py files as required, and My Python code runs without any problem.
I would really appreciate any hint.
Thanks !
EDIT :
Finally solved the problem. @mata had the right solution (although I had tried these lines before posting here).
The actual problem was coming from the fact that py2exe starts by copying my py files in
C:\Python27\Lib\site-packages
and apparently use them to create the exe. During creation, they are compiled to .pyc.
Further creation of the executable was skipping the compilation because the site-packages folder was already containing .pyc files.
I found a temporary solution in removing those files using an ant target before building, but I wonder whether this is good pratice or not.
Shouldn't py2exe avoid copying anything into the site-packages until I reached stable state ?
Solution
instead of:
import lib.exif as exif
try:
import facemovie.lib.exif as exif
# or
from facemovie.lib import exif