By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

[pyinstaller] how to compile Python script importing module

P: 2
Hi,

I need to compile a pyhton tool into an executable as the destination plateform (Solaris, Linux) are not deployed with Python or not all needed modules.

I found pyinstaller and follow the classical tutorial.

First executable starts correctly under Linux but not under windows.

Second it crashes right after due to unknown module that haev to be loaded.

Here is a view of my tool. The following code comes from analyzer.py I have to call to run this tool.

Expand|Select|Wrap|Line Numbers
  1. try:
  2.     TOOLS_ROOT = os.environ['TOOLS_ROOT']
  3.     sys.path.append(TOOLS_ROOT)
  4. except KeyError:
  5.     print 'TOOLS_ROOT is undefined. Please set it.'
  6.     sys.exit(1)
  7.  
  8. import lib.globals
  9. from lib.parserLib import Architecture
  10. import thread
  11. import threading
  12. ...
  13.  
here is directory architecture

/tool/__init__.py
analyzer.py
lib/__init__.py
globals.py
parserLib.py
Few questions:

- how to bypass the TOOLS_ROOT env var decalaration, that I used when I run directly analyzer.py under linux ?
Here is output of the script if I do not declare this ver
"""
vmintegration:~/pyinstaller-1.4/analyzer# ./dist/analyzer
TOOLS_ROOT is undefined. Please set it.
vmintegration:~/pyinstaller-1.4/analyzer#
"""

- how to indicate to pyinstaller that modules have to be included into the executable file, because they are currently not recognized
Here is output of the script when TOOLS_ROOT is defined (with a fake value)
"""
vmintegration:~/pyinstaller-1.4/analyzer# export TOOLS_ROOT=`pwd`
vmintegration:~/pyinstaller-1.4/analyzer# ./dist/analyzer
Traceback (most recent call last):
File "<string>", line 21, in <module>
File "/root/pyinstaller-1.4/iu.py", line 455, in importHook
raise ImportError, "No module named %s" % fqname
ImportError: No module named lib
"""

- how to integrate argument from command line if I need ?
Here is output of the script if TOOLS_ROOT is defined to the "real" root of my tool
"""
vmintegration:~/pyinstaller-1.4/analyzer# export TOOLS_ROOT=/home/stephane/tool
vmintegration:~/pyinstaller-1.4/analyzer# ./dist/analyzer
ERROR : Arg <opt> missing in command line ****
"""



I attached warnlog file to help me.



Here is the spec content file
"""
# -*- mode: python -*-
a = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'), os.path.join(HOMEPATH,'support/useUnicode.py'), '/home/stephane/python/script/analyzer.py'],
pathex=['/root/pyinstaller-1.4'])
pyz = PYZ(a.pure)
exe = EXE( pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=os.path.join('dist', 'analyzer'),
debug=False,
strip=False,
upx=True,
console=1 )
"""



Thanks for any help.
I read some documentation about pyinstaller but it's not very clear for me and I'm not able to progress anynmore.

Regards
Attached Files
File Type: txt warnanalyzer.txt (2.3 KB, 340 views)
Apr 19 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.