Hi,
I am trying to freeze my first python application.
When I run it from terminal without cx_Freeze everything is fine.
When I python setup.py build then build/exe.linux-x86_64-2.7/py_exe-app,
I get an ImportError :
Traceback (most recent call last):
File
"/home/duck/.pyenv/versions/splsdk/lib/python2.7/site-packages/cx_Freeze/initscripts/__startup__.py",
line 12, in <module>
__import__(name + "__init__")
File
"/home/duck/.pyenv/versions/splsdk/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py",
line 24, in <module>
exec(code, m.__dict__)
File "py_exe/app.py", line 6, in <module>
import utils
ImportError: No module named utils
As you can see, pyenv is used to build the frozen application.
Application tree :
+-- py_exe
| +-- app.py
| +-- __init__.py
| +-- tests
| +-- utils.py
+-- README.rst
+-- setup.py
As far as I understood, the difference between frozen execution and
standard python one is a difference in sys.path
standard execution sys.path :
['/home/duck/repositories/tools/py_exe',
'/home/duck/.pyenv/versions/splsdk/lib/python27.zip',
'/home/duck/.pyenv/versions/splsdk/lib/python2.7',
'/home/duck/.pyenv/versions/splsdk/lib/python2.7/plat-linux2',
'/home/duck/.pyenv/versions/splsdk/lib/python2.7/lib-tk',
'/home/duck/.pyenv/versions/splsdk/lib/python2.7/lib-old',
'/home/duck/.pyenv/versions/splsdk/lib/python2.7/lib-dynload',
'/home/duck/.pyenv/versions/2.7.11/lib/python2.7',
'/home/duck/.pyenv/versions/2.7.11/lib/python2.7/plat-linux2',
'/home/duck/.pyenv/versions/2.7.11/lib/python2.7/lib-tk',
'/home/duck/.pyenv/versions/splsdk/lib/python2.7/site-packages']
cx_Freeze execution sys.path :
['/home/duck/repositories/tools/build/exe.linux-x86_64-2.7',
'/home/duck/repositories/tools/build/exe.linux-x86_64-2.7/lib/python27.zip',
'/home/duck/repositories/tools/build/exe.linux-x86_64-2.7/lib/python2.7/',
'/home/duck/repositories/tools/build/exe.linux-x86_64-2.7/lib/python2.7/plat-linux2',
'/home/duck/repositories/tools/build/exe.linux-x86_64-2.7/lib/python2.7/lib-tk',
'/home/duck/repositories/tools/build/exe.linux-x86_64-2.7/lib/python2.7/lib-old',
'/home/duck/repositories/tools/build/exe.linux-x86_64-2.7/lib/python2.7/lib-dynload']
setup.py
# -*- coding: utf-8
from cx_Freeze import setup, Executable
silent = True
# Dependencies are automatically detected, but some modules need help.
buildOptions = dict(
packages = [],
excludes = [],
# We can list binary includes here if our target environment is missing
them.
bin_includes = [],
)
executables = [
Executable(
'py_exe/app.py',
base = None,
targetName = 'py_exe-app',
)
]
# On appelle la fonction setup
setup(
name = "py_exe-app",
version = "0.1",
description = """Testing cx_Freeze to easily deploy python programs \
developed with pyenv-virtualenv.""",
options = dict(build_exe = buildOptions),
executables = executables,
)
py_exe/utils.py
# -*- coding: utf-8
def sum(a,b):
return a + b
py_exe/app.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import pprint
pprint.pprint(sys.path)
import utils
def main():
sys.stdout.write('Running python version : {}\n'.format(sys.version))
sys.stdout.write('Executing file {}\n'.format(__file__))
sys.stdout.write('Sum 2, 3 using utils.sum\n')
sys.stdout.write("Result : {}\n".format(str(utils.sum(3,2))))
sys.stdout.write('Quit.\n')
sys.exit(0)
main()
#if __name__ == '__main__':
# main()
What did I missed ?
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
cx-freeze-users mailing list
cx-freeze-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cx-freeze-users