I'm hoping that someone here can point me in the right direction with
freezing my Flask application. I'm using the latest git
version: 2.1dev-d649f53 (But it fails on 2.0 as well). I'm on a Mac using
10.7.5 and Python 2.7.
Note that to get to this point I had to do 2 things:
1) Change werkzeug lazy imports in __init__.py to be normal imports
2) Add an empty __init__.py module to flaskext so that the babel extension
is detected
Here is the output I get from PyInstaller:
(packaging)DaveMacBookPro:pyinstaller-dev dmckeone$ python pyinstaller.py
-F ../pyinstaller-tests/simple_app_babel.py
14 INFO: wrote
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/simple_app_babel.spec
35 WARNING: You are running 64-bit Python: created binaries will only work
on Mac OS X 10.6+.
If you need 10.4-10.5 compatibility, run Python as a 32-bit binary with
this command:
VERSIONER_PYTHON_PREFER_32_BIT=yes arch -i386
/Users/dmckeone/Envs/packaging/bin/python
4044 INFO: UPX is not available.
5004 INFO: checking Analysis
5004 INFO: building Analysis because out00-Analysis.toc non existent
5004 INFO: running Analysis out00-Analysis.toc
5017 INFO: Analyzing
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/support/_pyi_bootstrap.py
5962 INFO: Analyzing
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_archive.py
6024 INFO: Analyzing
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_carchive.py
6088 INFO: Analyzing
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_iu.py
6109 INFO: Analyzing ../pyinstaller-tests/simple_app_babel.py
7499 INFO: checking Tree
7499 INFO: building because out00-Tree.toc missing or bad
7499 INFO: building Tree out00-Tree.toc
7570 INFO: checking Tree
7570 INFO: building because out01-Tree.toc missing or bad
7570 INFO: building Tree out01-Tree.toc
8865 INFO: Hidden import 'encodings' has been found otherwise
8865 INFO: Looking for run-time hooks
8866 INFO: Analyzing rthook
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/support/rthooks/pyi_rth_encodings.py
8915 INFO: Analyzing rthook
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/support/rthooks/pyi_rth_Tkinter.py
8959 INFO: Analyzing rthook
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/support/rthooks/pyi_rth_babel.py
9287 INFO: Looking for Python library Python
9287 INFO: Looking for Python library in
/System/Library/Frameworks/Python.framework/Versions/2.7
9326 INFO: Warnings written to
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/warnsimple_app_babel.txt
9348 INFO: checking PYZ
9348 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
9349 INFO: building PYZ out00-PYZ.toc
11149 INFO: checking PKG
11149 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
11149 INFO: building PKG out00-PKG.pkg
14622 INFO: checking EXE
14622 INFO: rebuilding out00-EXE.toc because simple_app_babel missing
14622 INFO: building EXE from out00-EXE.toc
14624 INFO: Appending archive to EXE
/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/dist/simple_app_babel
and the resulting traceback when I run the application:
Traceback (most recent call last):
File "<string>", line 7, in <module>
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_iu.py",
line 386, in importHook
mod = _self_doimport(nm, ctx, fqname)
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_iu.py",
line 480, in doimport
exec co in mod.__dict__
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/babel",
line 33, in <module>
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_iu.py",
line 386, in importHook
mod = _self_doimport(nm, ctx, fqname)
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/PyInstaller/loader/pyi_iu.py",
line 480, in doimport
exec co in mod.__dict__
File
"/var/folders/12/ln03t1tj0nx1k65fpd1pcbj80000gn/T/_MEIlY2Q1H/eggs/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
line 698, in <module>
File
"/var/folders/12/ln03t1tj0nx1k65fpd1pcbj80000gn/T/_MEIlY2Q1H/eggs/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
line 701, in Environment
File
"/var/folders/12/ln03t1tj0nx1k65fpd1pcbj80000gn/T/_MEIlY2Q1H/eggs/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
line 99, in get_supported_platform
File
"/var/folders/12/ln03t1tj0nx1k65fpd1pcbj80000gn/T/_MEIlY2Q1H/eggs/setuptools-0.6c11-py2.7.egg/pkg_resources.py",
line 209, in _macosx_vers
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/platform",
line 803, in mac_ver
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/platform",
line 780, in _mac_ver_xml
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/plistlib",
line 78, in readPlist
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/plistlib",
line 406, in parse
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/plistlib",
line 418, in handleEndElement
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/plistlib",
line 452, in end_key
File
"/Users/dmckeone/PersonalProgramming/Python/pyinstaller-dev/simple_app_babel/build/pyi.darwin/simple_app_babel/out00-PYZ.pyz/plistlib",
line 436, in getData
*LookupError: no codec search functions registered: can't find encoding*
Here is the application:
from flask import Flask
from flaskext.babel import Babel, format_datetime
from datetime import datetime
from mypackage.database import MyDatabase
app = Flask(__name__)
bab = Babel(app)
class DemoDatabase(MyDatabase):
def set_connection_parameters(self):
self.connection_uri = 'postgresql://[email protected]/Demo'
self.engine_options['echo'] = True
db = DemoDatabase()
db.init()
@app.teardown_request
def shutdown_session(exception=None):
db.session_remove()
@app.route('/')
def root():
return u"Hello (Frozen) World!"
@app.route('/users')
def user_list():
columns = [User.first_name, User.last_name]
response = u""
users = db.session.query(*columns)
for user in users:
response += u"<br>" + user.first_name + " " + user.last_name
return response
@app.route('/date')
def date():
return u"Hello (Frozen) World! It is
{0}".format(format_datetime(datetime.now()))
if __name__ == '__main__':
app.run()
I can't quite pin down which area is causing this error, or where to start
looking. The application uses SQLAlchemy, Dogpile.cache, and PyCrypto 3rd
party packages (the rest are all from the standard library). What's
interesting is that if I run an app using my package, but not Flask-Babel,
then it works:
from flask import Flask
from mypackage.database import MyDatabase
from mypackage.models import User
app = Flask(__name__)
class DemoDatabase(MyDatabase):
def set_connection_parameters(self):
self.connection_uri = 'postgresql://[email protected]/Demo'
self.engine_options['echo'] = True
db = DemoDatabase()
db.init()
@app.teardown_request
def shutdown_session(exception=None):
db.session_remove()
@app.route('/')
def root():
return u"Hello (Frozen) World!"
@app.route('/users')
def user_list():
columns = [User.first_name, User.last_name]
response = u""
users = db.session.query(*columns)
for user in users:
response += u"<br>" + user.first_name + " " + user.last_name
return response
if __name__ == '__main__':
app.run()
It also works using Flask-Babel, but not my package:
from datetime import datetime
from flaskext.babel import Babel, format_datetime
from flask import Flask
app = Flask(__name__)
Babel(app)
@app.route('/')
def root():
return u"Hello (Frozen) World! It is
{0}".format(format_datetime(datetime.now()))
if __name__ == '__main__':
app.run()
So it is just some combination of Flask-Babel and something in my package
that is causing some kind of conflict. Any help or traceback deciphering
would be greatly appreciated!
--
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pyinstaller/-/fcVfndaLFxIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyinstaller?hl=en.