Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 1st, 2005, 09: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, 02: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,676 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 13 h 50 m 24 sec
Reputation Power: 68
Send a message via AIM to Yegg`
Hmm, did you try reinstalling SAPI?

Reply With Quote
  #3  
Old August 2nd, 2005, 09: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
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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway