I'm not sure exactly what code should I post. The spec file is kind of
complex itself, I guess I could atach it here. The problem should reproduce
if you try to package any project that has a `from tables import *` or
`import tables`. `tables` itself has cython as a dependency and at least to
me that seems to cause the problem I posted.
So far I just excluded cython from the included packages and that seemed to
fix problem for the moment.
luni, 19 martie 2012, 22:39:40 UTC+2, Martin Z a scris:
>
> Bogdan.Neacsa píše v Po 19. 03. 2012 v 07:19 -0700:
> > Now is this some kind of problem that will be fixed? Better has anyone
> > manage to package a project with pytables/cython dependencies and if
> > so, how?
>
> I don't know about any cython project.
> But could you please post any code example to be able to reproduce this
> error?
>
>
--
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/-/-r-txhD8rX0J.
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.
# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""
The resulting structure of the distribution will be:
{current folder} / TVB_Linux_{version}_x32_web.zip
Accepted argument: 'cluster'
"""
# __future__ import must be kept at the begining of the file
from __future__ import with_statement
import os
import sys
import shutil
import zipfile
import matplotlib
import tvb
BASE_FOLDER = os.path.join(os.path.dirname(os.path.dirname(tvb.__file__)),
'dist-tvb')
DATA_FOLDER = 'tvb_data'
APP_NAME = 'start_tvb'
ARG_CLUSTER = 'cluster'
"""
The required packages for tvb.
We need to copy them separately because of pyinstaller limitations on including
data files and using them in porcesses opened by the external 'python2.6'.
"""
TVB_DEPENDENCIES = ['apscheduler', 'bin', 'cherrypy', 'cfflib', 'dateutil',
'decorator', 'formencode', 'genshi', 'lxml', 'matplotlib',
'migrate', 'mod_pywebsocket', 'mplh5canvas', 'numpy',
'networkx', 'nibabel', 'numexpr', 'pysqlite2', 'pytz',
'psycopg2', 'sqlalchemy', 'simplejson', 'scipy',
'scikits', 'tvb', 'tempita', 'tables', 'h5py']
PYTHON_PATH = None
if 'PYTHONPATH' in os.environ:
PYTHON_PATH = os.environ['PYTHONPATH']
else:
try:
PYTHON_PATH = os.path.dirname(os.__file__).replace('/lib/', '/bin/')
except Exception, _:
PYTHON_PATH = None
if PYTHON_PATH is None:
print 'PYTHONPATH environment variable not set, and python executable location could not be deduced.'
print 'Please set "export PYTHONPATH=$path/$to/python2.6" then try again!'
exit()
def create_trees_from_dependencies(dep_list):
"""
Given a dependency list, create pyinstaller specific Tree objects that will be used by the COLLECT class.
"""
result = []
for one_dep in dep_list:
exec 'import ' + one_dep + ' as module_import'
file_path = module_import.__file__
tree_path = os.path.dirname(file_path)
if not os.path.isdir(tree_path):
import zipfile
dir_path = os.path.dirname(file_path)
zip_name, actual_module = dir_path.split('.egg')
actual_module = actual_module[1:]
zip_name = zip_name + '.egg'
dest_path = 'temp'
source_zip = zipfile.ZipFile(zip_name, 'r')
for name in source_zip.namelist():
if name.endswith('.py'):
source_zip.extract(name, dest_path)
source_zip.close()
#shutil.rmtree('temp')
#EGG are ussually structured as package_name.egg/package_name/actual_package
tree_path = os.path.join(dest_path, actual_module)
print "Tree path is " + str(tree_path)
result.append(Tree(tree_path, prefix=one_dep, excludes=['*.pyc', '.svn', '.DStore', '*.svn*', '*.DS*']))
return result
'''
Analyze run.py and rpserver.py separately from app.py because an additional include will cause mplh5server to timeout, and editing app.py
after creation will not help due to the way pyinstaller creates it's executable.
'''
TVB_ROOT = os.path.split(os.path.dirname(tvb.__file__))[0]
a1 = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'),
os.path.join(HOMEPATH,'support/useUnicode.py'),
TVB_ROOT + '/bin/app.py'],
pathex=['/home/tester/TVB/pyinstaller-1.5.1'],
excludes=['cython', 'Cython'])
a2 = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'),
os.path.join(HOMEPATH,'support/useUnicode.py'),
TVB_ROOT + '/tvb/interfaces/web/run.py',
TVB_ROOT + '/bin/rpserver.py',
TVB_ROOT + '/tvb/datatypes/connectivity.py'],
pathex=['/home/tester/TVB/pyinstaller-1.5.1'],
excludes=['cython', 'Cython'])
'''
Exclude unneeded modules from app.py dependencies as these will only be used by the subprocesses started with the external python2.6.
'''
exclude_tvb = [x for x in a1.pure if not (x[0].startswith('cherrypy')
or x[0].startswith('email.mime')
or x[0].startswith('matplotlib')
or x[0].startswith('migrate')
or x[0].startswith('mplh5canvas')
or x[0].startswith('sqlalchemy')
or x[0].startswith('tvb')
or x[0].startswith('tables')
or x[0].startswith('h5py'))]
pyz = PYZ(TOC(exclude_tvb))
exe = EXE(pyz,
a1.scripts,
exclude_binaries=1,
name=os.path.join('build/pyi.linux2/' + BASE_FOLDER, APP_NAME),
debug=False,
strip=False,
upx=True,
console=1 )
'''
Additional modules required for the external python.
'''
python_tree = Tree(os.path.dirname(os.__file__), excludes=['*.pyc*', '*.svn*'])
additional_trees = create_trees_from_dependencies(TVB_DEPENDENCIES)
coll = COLLECT( exe,
a1.binaries,
a1.zipfiles,
a1.datas,
a2.binaries,
a2.zipfiles,
a2.datas,
python_tree,
*additional_trees,
strip=False,
upx=True,
name=os.path.join(BASE_FOLDER, DATA_FOLDER))
'''
Some extra requirements like matplotlib data, or module not added so far are also needed.
'''
if not os.path.exists(os.path.join(BASE_FOLDER, DATA_FOLDER)):
os.makedirs(os.path.join(BASE_FOLDER, DATA_FOLDER))
shutil.copy(PYTHON_PATH, os.path.join(BASE_FOLDER, DATA_FOLDER, 'python2.6'))
mpl_data_folder = os.path.join(BASE_FOLDER, DATA_FOLDER, 'mpl-data')
if os.path.exists(mpl_data_folder):
shutil.rmtree(mpl_data_folder)
matplotlib.use('TkAgg')
import pylab
shutil.copytree(matplotlib._get_data_path(), mpl_data_folder)
import pkg_resources
file_path = pkg_resources.__file__
if not os.path.isdir(os.path.dirname(file_path)):
zip_name = file_path.split('.egg')[0]
zip_name = zip_name + '.egg'
dest_path = os.path.join('temp', 'pkg_res')
source_zip = zipfile.ZipFile(zip_name, 'r')
for name in source_zip.namelist():
if name.endswith('pkg_resources.py'):
source_zip.extract(name, dest_path)
file_path = os.path.join(dest_path, name)
source_zip.close()
shutil.copy(file_path.replace('.pyc', '.py'), os.path.join(BASE_FOLDER, DATA_FOLDER, 'pkg_resources.py'))
import decorator
shutil.copy(decorator.__file__.replace('.pyc', '.py'), os.path.join(BASE_FOLDER, DATA_FOLDER, 'decorator.py'))
shutil.copy(pylab.__file__.replace('.pyc', '.py'), os.path.join(BASE_FOLDER, DATA_FOLDER, 'pylab.py'))
shutil.copy(matplotlib.matplotlib_fname(), os.path.join(BASE_FOLDER, DATA_FOLDER, 'matplotlibrc'))
shutil.rmtree(os.path.join(BASE_FOLDER, DATA_FOLDER, 'dist-packages'), True)
shutil.rmtree(os.path.join(BASE_FOLDER, DATA_FOLDER, 'lib2to3'), True)
export_text = """# make sure system knows where our libraries are
if [ ${LD_LIBRARY_PATH+1} ]; then
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
else
export LD_LIBRARY_PATH=`pwd`
fi
if [ ${LD_RUN_PATH+1} ]; then
export LD_RUN_PATH=`pwd`:LD_RUN_PATH
else
export LD_RUN_PATH=`pwd`
fi
"""
COMMAND = open(os.path.join(BASE_FOLDER, 'tvb_start.sh'), 'w')
COMMAND.write('cd ' + DATA_FOLDER + '\n')
COMMAND.write(export_text)
COMMAND.write('./' + APP_NAME + '\n')
COMMAND.close()
os.chmod(os.path.join(BASE_FOLDER, 'tvb_start.sh'), 0775)
COMMAND = open(os.path.join(BASE_FOLDER, 'tvb_clean.sh'), 'w')
COMMAND.write('cd ' + DATA_FOLDER + '\n')
COMMAND.write(export_text)
COMMAND.write('./' + APP_NAME + ' clean')
COMMAND.close()
os.chmod(os.path.join(BASE_FOLDER, 'tvb_clean.sh'), 0775)
COMMAND = open(os.path.join(BASE_FOLDER, 'tvb_stop.sh'), 'w')
COMMAND.write('cd ' + DATA_FOLDER + '\n')
COMMAND.write(export_text)
COMMAND.write('./' + APP_NAME + ' stop')
COMMAND.close()
os.chmod(os.path.join(BASE_FOLDER, 'tvb_stop.sh'), 0775)
if ARG_CLUSTER in sys.argv:
COMMAND = open(os.path.join(BASE_FOLDER, 'clusterLauncher'), 'w')
COMMAND.write(open("bin/cluster_launch.sh", 'r').read())
COMMAND.close()
os.chmod(os.path.join(BASE_FOLDER, 'clusterLauncher'), 0775)
COMMAND = open(os.path.join(BASE_FOLDER, 'clusterSetup.sh'), 'w')
COMMAND.write('#!/bin/sh\n')
COMMAND.write("echo 'export TVB_ROOT=`pwd`' >> $HOME/.profile\n")
COMMAND.write("echo '\n' >> $HOME/.profile\n")
COMMAND.write("echo 'export PATH=$TVB_ROOT:$PATH' >> $HOME/.profile\n")
COMMAND.write(". $HOME/.profile\n")
COMMAND.close()
os.chmod(os.path.join(BASE_FOLDER, 'clusterSetup.sh'), 0775)
sys.argv.remove(ARG_CLUSTER)
try:
from setup import generate_final_zip
os.rename(BASE_FOLDER, os.path.join(os.path.dirname(BASE_FOLDER), 'dist'))
shutil.rmtree('temp', True)
generate_final_zip('TVB_Linux', DATA_FOLDER)
except Exception, excep:
print excep
print "!! Can not import/execute from setup.py!!!"
exit(1)