Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 1st, 2005, 10:05 AM
Pennywaffer Pennywaffer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Amsterdam, the Netherlands
Posts: 12 Pennywaffer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 4 sec
Reputation Power: 0
py2exe and external files

I've only recently started working with Python, so since this is all fairly new to me forgive me for asking a beginner question.

1. My module makes use of the modules pyTTS , which requires the Microsoft Speech API (SAPI), and pySonic , which requires a specific DLL file (fmod.dll) to be present in the system32 folder. I've installed these things and it works fine
However:

I use py2exe to create a standalone version of my program, using the following setup script:

Code:
from distutils.core import setup
import py2exe
setup(name='test', version='0.1.0', py_modules=['test'],windows=['test.py'])


I then create the standalone version using

Code:
python setup.py py2exe


This executes without errors, but when I want to open the created exe in the 'dist' folder and error is logged, which is either

Traceback (most recent call last):
File "test.py", line 19, in ?
File "pyTTS\__init__.pyc", line 28, in Create
ValueError: "SAPI" not supported

or

Traceback (most recent call last):
File "test.py", line 11, in ?
File "pySonic.pyx", line 975, in pySonic.FileSample.__new__
pySonic.FMODError: File not found.


depending on which occurs first. These errors normally occur when the abovementioned files (SAPI and fmod.dll) are not present, which means that whoever wants to use my standalone version must first install them. But the problem here is that they are already installed and yet I still get the errors. This doesn't happen when I run the original .py file using python, only when I run the exe created by py2exe.

Of course this problem doesn't really have anything to do with pySonic or pyTTS, but is rather related to the fact that somehow py2exe doesn't include access to files outside the package directory. Does anybody know to fix this?, I have so little experience with Python that it's difficult to find out what I'm doing wrong. I mean the files are there so I don't understand why they would be accessible through my original script and not through the standalone version of it.

Thanks!

Reply With Quote
  #2  
Old August 1st, 2005, 03:39 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,797 Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level)Yegg` User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 21 h 54 m 27 sec
Reputation Power: 152
Send a message via AIM to Yegg`
Hmm, did you try reinstalling SAPI?

Reply With Quote
  #3  
Old August 2nd, 2005, 10:18 PM
Pennywaffer Pennywaffer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Amsterdam, the Netherlands
Posts: 12 Pennywaffer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 4 sec
Reputation Power: 0
For the record, I solved the problem although it took me quite a few hours to figure it out.

It turns out that the above mentioned pyTTS module imports the win32com.client module (part of the Python Win32 Extensions, which allow interaction with the windows environment and COM objects). To communicate with a specific Windows application the makepy.py module (also part of the win32 extensions) has to make a module that maps to the application's library, which in this case was 'Microsoft Speech Object Library'. This generated .py file is not automatically included by py2exe, so you have to tell it to do so by adding an extra option to the setup call in your setup file. This option needs some specific values for the application in question which can be retrieved by running makepy.py with the -i flag

so in this case I had to run:

Code:
python makepy.py -i "Microsoft Speech Object Library"


which yielded:

Code:
Microsoft Speech Object Library
 {C866CA3A-32F7-11D2-9602-00C04F8EE628}, lcid=0, major=5, minor=0
 >>> # Use these commands in Python code to auto generate .py support
 >>> from win32com.client import gencache
 >>> gencache.EnsureModule('{C866CA3A-32F7-11D2-9602-00C04F8EE628}', 0, 5, 0)


I then used these values in my setup call:

Code:
setup(	name='test', 
		version='0.1.0', 
		py_modules=['test'],
		windows=['test.py'],
		options={"py2exe": {"typelibs": [('{C866CA3A-32F7-11D2-9602-00C04F8EE628}',0,5,0)]}}
		)


This makes py2exe include the application specific file 'C866CA3A-32F7-11D2-9602-00C04F8EE628x0x5x0.py'.

With this file present, everything works great. So, if you ever have to make use of win32 stuff and it isn't working after you use py2exe, check whether your modules access application specific data which require makepy to be run first.

It could save you quite some time!
Comments on this post
sf2k agrees: great information! may come in handy
Grim Archon agrees: Very useful, good solid info.

Reply With Quote
  #4  
Old September 2nd, 2010, 09:47 AM
quentinsf quentinsf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2010
Posts: 1 quentinsf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 36 sec
Reputation Power: 0
PennyWaffer -

Thank you so much - I can't think how many hours you must have saved me!

Reply With Quote
  #5  
Old September 12th, 2010, 04:58 AM
daluu daluu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 6 daluu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by Pennywaffer
For the record, I solved the problem although it took me quite a few hours to figure it out.

It turns out that the above mentioned pyTTS module imports the win32com.client module (part of the Python Win32 Extensions, which allow interaction with the windows environment and COM objects). To communicate with a specific Windows application the makepy.py module (also part of the win32 extensions) has to make a module that maps to the application's library, which in this case was 'Microsoft Speech Object Library'. This generated .py file is not automatically included by py2exe, so you have to tell it to do so by adding an extra option to the setup call in your setup file. This option needs some specific values for the application in question which can be retrieved by running makepy.py with the -i flag

so in this case I had to run:

Code:
python makepy.py -i "Microsoft Speech Object Library"


which yielded:

Code:
Microsoft Speech Object Library
 {C866CA3A-32F7-11D2-9602-00C04F8EE628}, lcid=0, major=5, minor=0
 >>> # Use these commands in Python code to auto generate .py support
 >>> from win32com.client import gencache
 >>> gencache.EnsureModule('{C866CA3A-32F7-11D2-9602-00C04F8EE628}', 0, 5, 0)


I then used these values in my setup call:

Code:
setup(	name='test', 
		version='0.1.0', 
		py_modules=['test'],
		windows=['test.py'],
		options={"py2exe": {"typelibs": [('{C866CA3A-32F7-11D2-9602-00C04F8EE628}',0,5,0)]}}
		)


This makes py2exe include the application specific file 'C866CA3A-32F7-11D2-9602-00C04F8EE628x0x5x0.py'.

With this file present, everything works great. So, if you ever have to make use of win32 stuff and it isn't working after you use py2exe, check whether your modules access application specific data which require makepy to be run first.

It could save you quite some time!


Have you tried running the binary on a few other Windows PCs with "Microsoft Speech Object Library" installed (if that's not installed by default by Windows)?

The compilation process looks to me like it references a COM GUID, which I believe may be unique on each PC? So the GUID for "Microsoft Speech Object Library" may be different for different PCs. If that was true, one would need to rebuild or make the COM GUID python binding on each PC to deploy for.

http://en.wikipedia.org/wiki/Globally_unique_identifier

Hopefully, I'm wrong.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > py2exe and


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap