|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
Hmm, did you try reinstalling SAPI?
|
|
#3
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > py2exe and |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|