473,554 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Bad file descriptor" after py2exe or Installer

Hello,

I had a strange problem when freezing (using either py2exe or McMillan
installer) a script that imports reportlab (which imports PIL (which
imports FixTk))).

- Python 2.3.3c (also with Python 2.3)
- PIL 1.1.4
- Installer or py2exe : latest versions.

Here is how I can reproduce it on a Win2000 and on a Win XP machine. I
also found a hack that works for me, but have no idea why all this happens.

The following script `test.py` runs without problem when interpreted:

print "before"
from PIL import Image
print "after"

Output as expected:

c:\test>python test.py
before
after
c:\test>

But if I freeze it and invoke the `test.exe`, I get a strange
behaviour::

c:\test\dist> test
before
c:\test\dist>

The second print just does not happen. And if I redirect stderr to a
file, I see a bit more::

c:\test\dist> test 2> tmp.txt
before
c:\test\dist> type tmp.txt
Traceback (most recent call last):
File "test.py", line 3, in ?
print "after"
IOError: [Errno 9] Bad file descriptor
c:\test\dist>

Workaround:
If I remove the following lines (41-46) of PIL/Image.py::

try:
# give Tk a chance to set up the environment, in case we're
# using an _imaging module linked against libtcl/libtk
import FixTk
except ImportError:
pass

then the problem disappears, and both script and executable work for
me...

If somebody sees an explanation, please let me know!

Luc Saffre

Jul 18 '05 #1
6 3934
On 11/12/2003 23:11, Thomas Heller wrote:
It seems I cannot reproduce this with py2exe 0.5.
Can you?


Yes: I use py2exe 0.5.0a5.

Here is in more detailed, how I reproduce the problem:

I used the following installers:
Python-2.3.3c1.exe
PIL-1.1.4.win32-py2.3.exe
py2exe-0.5.0a5.win32-py2.3.exe
I installed these three to a clean installation (except for my windows
registry where I don't know how to verify cleaness)

I place the test.py as described into a separate directory, together
with a file setup.py:

from distutils.core import setup
import py2exe
setup( console=["test.py"] )

and then I type "setup py2exe" at the command line.
Here is the output of that command:

running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension '_sre'
creating python loader for extension 'PIL._imaging'
creating python loader for extension '_tkinter'
creating python loader for extension 'PIL._imagingtk '
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Pa letteFile.py to PIL\PaletteFile .pyc
skipping byte-compilation of C:\PYTHON23\lib \lib-tk\FixTk.py to FixTk.pyc
skipping byte-compilation of C:\PYTHON23\lib \copy_reg.py to copy_reg.pyc
skipping byte-compilation of C:\PYTHON23\lib \sre_compile.py to
sre_compile.pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Im ageChops.py to PIL\ImageChops. pyc
skipping byte-compilation of C:\PYTHON23\lib \StringIO.py to StringIO.pyc
byte-compiling
T:\data\luc\rel ease\lino\tests \py2exe\build\b dist.win32\wine xe\temp\_sre.py
to _sre.pyc
skipping byte-compilation of C:\PYTHON23\lib \macpath.py to macpath.pyc
skipping byte-compilation of C:\PYTHON23\lib \popen2.py to popen2.pyc
skipping byte-compilation of C:\PYTHON23\lib \atexit.py to atexit.pyc
skipping byte-compilation of C:\PYTHON23\lib \dummy_thread.p y to
dummy_thread.py c
byte-compiling
T:\data\luc\rel ease\lino\tests \py2exe\build\b dist.win32\wine xe\temp\PIL._im aging.py
to PIL\_imaging.py c
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Im ageFilter.py to PIL\ImageFilter .pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Gi mpGradientFile. py to
PIL\GimpGradien tFile.pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\__ init__.py to PIL\__init__.py c
skipping byte-compilation of C:\PYTHON23\lib \posixpath.py to posixpath.pyc
byte-compiling
T:\data\luc\rel ease\lino\tests \py2exe\build\b dist.win32\wine xe\temp\_tkinte r.py
to _tkinter.pyc
skipping byte-compilation of C:\PYTHON23\lib \linecache.py to linecache.pyc
skipping byte-compilation of C:\PYTHON23\lib \tempfile.py to tempfile.pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Gi mpPaletteFile.p y to
PIL\GimpPalette File.pyc
skipping byte-compilation of C:\PYTHON23\lib \sre_constants. py to
sre_constants.p yc
skipping byte-compilation of C:\PYTHON23\lib \re.py to re.pyc
skipping byte-compilation of C:\PYTHON23\lib \ntpath.py to ntpath.pyc
skipping byte-compilation of C:\PYTHON23\lib \stat.py to stat.pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Im agePalette.py to PIL\ImagePalett e.pyc
skipping byte-compilation of C:\PYTHON23\lib \lib-tk\Tkinter.py to
Tkinter.pyc
skipping byte-compilation of C:\PYTHON23\lib \string.py to string.pyc
skipping byte-compilation of C:\PYTHON23\lib \warnings.py to warnings.pyc
skipping byte-compilation of C:\PYTHON23\lib \UserDict.py to UserDict.pyc
skipping byte-compilation of C:\PYTHON23\lib \site-packages\PIL\Im age.py
to PIL\Image.pyc
skipping byte-compilation of C:\PYTHON23\lib \repr.py to repr.pyc
byte-compiling
T:\data\luc\rel ease\lino\tests \py2exe\build\b dist.win32\wine xe\temp\PIL._im agingtk.py
to PIL\_imagingtk. pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Im ageTk.py to PIL\ImageTk.pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Im ageTransform.py to
PIL\ImageTransf orm.pyc
skipping byte-compilation of C:\PYTHON23\lib \copy.py to copy.pyc
skipping byte-compilation of
C:\PYTHON23\lib \site-packages\PIL\Im ageColor.py to PIL\ImageColor. pyc
skipping byte-compilation of C:\PYTHON23\lib \types.py to types.pyc
skipping byte-compilation of C:\PYTHON23\lib \sre.py to sre.pyc
skipping byte-compilation of C:\PYTHON23\lib \traceback.py to traceback.pyc
skipping byte-compilation of C:\PYTHON23\lib \lib-tk\Tkconstants. py to
Tkconstants.pyc
skipping byte-compilation of C:\PYTHON23\lib \random.py to random.pyc
skipping byte-compilation of C:\PYTHON23\lib \os2emxpath.py to os2emxpath.pyc
skipping byte-compilation of C:\PYTHON23\lib \colorsys.py to colorsys.pyc
skipping byte-compilation of C:\PYTHON23\lib \sre_parse.py to sre_parse.pyc
skipping byte-compilation of C:\PYTHON23\lib \os.py to os.pyc
*** copy extensions ***
copying C:\PYTHON23\DLL s\_sre.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\lib \site-packages\PIL\_i maging.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\DLL s\_tkinter.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\lib \site-packages\PIL\_i magingtk.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
*** copy dlls ***
copying u:\CYGWIN\BIN\c ygwin1.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying u:\CYGWIN\BIN\t k84.dll -> T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\WINNT\System 32\python23.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\DLL s\tcl84.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying u:\CYGWIN\BIN\t cl84.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\lib \site-packages\py2exe \run.exe ->
T:\data\luc\rel ease\lino\tests \py2exe\dist\te st.exe
copying C:\PYTHON23\lib \site-packages\py2exe \run_w.exe ->
T:\data\luc\rel ease\lino\tests \py2exe\dist\tk hello.exe

Afterwards the dist\test.exe shows the described behavious.

I hope that you (or somebody else) can now reproduce the problem.

TIA,
Luc

Jul 18 '05 #2
Luc Saffre <lu********@gmx .net> writes:
On 11/12/2003 23:11, Thomas Heller wrote:
> It seems I cannot reproduce this with py2exe 0.5.
> Can you?
Yes: I use py2exe 0.5.0a5.

Here is in more detailed, how I reproduce the problem:

I used the following installers:
Python-2.3.3c1.exe
PIL-1.1.4.win32-py2.3.exe
py2exe-0.5.0a5.win32-py2.3.exe
I installed these three to a clean installation (except for my windows
registry where I don't know how to verify cleaness)

I place the test.py as described into a separate directory, together
with a file setup.py:

from distutils.core import setup
import py2exe
setup( console=["test.py"] )

and then I type "setup py2exe" at the command line.
Here is the output of that command:


[...] *** copy extensions ***
copying C:\PYTHON23\DLL s\_sre.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\lib \site-packages\PIL\_i maging.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\DLL s\_tkinter.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\lib \site-packages\PIL\_i magingtk.pyd ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
*** copy dlls ***
I guess the problem is here:
copying u:\CYGWIN\BIN\c ygwin1.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying u:\CYGWIN\BIN\t k84.dll -> T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\WINNT\System 32\python23.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\DLL s\tcl84.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying u:\CYGWIN\BIN\t cl84.dll ->
T:\data\luc\rel ease\lino\tests \py2exe\dist
copying C:\PYTHON23\lib \site-packages\py2exe \run.exe ->
T:\data\luc\rel ease\lino\tests \py2exe\dist\te st.exe
copying C:\PYTHON23\lib \site-packages\py2exe \run_w.exe ->
T:\data\luc\rel ease\lino\tests \py2exe\dist\tk hello.exe


py2exe seems to pick up cygwin binaries. The reason could be that
either you have cygwin extensions somewhere in your pythonpath, or parts
of the PATH env variable points into the cygwin directories, or
something like that. You should look at the output above carefully, and
make sure that it is what one would expect.

HTH,

Thomas
Jul 18 '05 #3
On 12.12.2003 15:41, Thomas Heller wrote:
py2exe seems to pick up cygwin binaries. The reason could be that
either you have cygwin extensions somewhere in your pythonpath, or parts
of the PATH env variable points into the cygwin directories, or
something like that. You should look at the output above carefully, and
make sure that it is what one would expect.


That's it! Thank you, Thomas, your hint helped.

I had the Cygwin tcltk package installed. After removing this package
(using cygwin's setup.exe), I can use again the original PIL/Image.py
and everything works fine.

My PATH contains the cygwin bin directories:
PATH=u:\CYGWIN\ BIN;
c:\python23\Scr ipts;c:\python2 3;
....
u:\CYGWIN\USR\B IN;u:\CYGWIN\US R\LOCAL\BIN;...

Another workaround is to remove the cygwin directories from PATH:
I reinstalled the cygwin tcltk and the problem reappeared,
moving the first cygwin directory to come after the python directory did
not help. Then I removed those directories completely from PATH (during
the build) and the problem disappeared again.

I would consider this as a bug (in both py2exe and Installer) since they
decide to pick some cygwin tcl/tk dll's who happen to hang around while
the Python runtime won't...

Luc

Jul 18 '05 #4
Luc Saffre <lu********@gmx .net> writes:
On 12.12.2003 15:41, Thomas Heller wrote:
py2exe seems to pick up cygwin binaries. The reason could be that
either you have cygwin extensions somewhere in your pythonpath, or parts
of the PATH env variable points into the cygwin directories, or
something like that. You should look at the output above carefully, and
make sure that it is what one would expect.


That's it! Thank you, Thomas, your hint helped.

I had the Cygwin tcltk package installed. After removing this package
(using cygwin's setup.exe), I can use again the original PIL/Image.py
and everything works fine.

My PATH contains the cygwin bin directories:
PATH=u:\CYGWIN\ BIN;
c:\python23\Scr ipts;c:\python2 3;
...
u:\CYGWIN\USR\B IN;u:\CYGWIN\US R\LOCAL\BIN;...

Another workaround is to remove the cygwin directories from PATH:
I reinstalled the cygwin tcltk and the problem reappeared,
moving the first cygwin directory to come after the python directory
did not help. Then I removed those directories completely from PATH
(during the build) and the problem disappeared again.

I would consider this as a bug (in both py2exe and Installer) since
they decide to pick some cygwin tcl/tk dll's who happen to hang around
while the Python runtime won't...


Yep, that's a bug.

Although I wonder: does it really make sense to include cygwin's path
into PATH? Isn't cygwin only usefull from within the cygwin prompt?

I tried cygwin some time ago, and was initially broken because I had
installed (native) mingw32 somewhere, so it seemed to me to better keep
cmd.exe and cygwin's paths separate from each other.

Thomas
Jul 18 '05 #5
[posted and mailed]

Luc Saffre <lu********@gmx .net> writes:
On 12.12.2003 15:41, Thomas Heller wrote:
py2exe seems to pick up cygwin binaries. The reason could be that
either you have cygwin extensions somewhere in your pythonpath, or parts
of the PATH env variable points into the cygwin directories, or
something like that. You should look at the output above carefully, and
make sure that it is what one would expect.


That's it! Thank you, Thomas, your hint helped.

I had the Cygwin tcltk package installed. After removing this package
(using cygwin's setup.exe), I can use again the original PIL/Image.py
and everything works fine.

My PATH contains the cygwin bin directories:
PATH=u:\CYGWIN\ BIN;
c:\python23\Scr ipts;c:\python2 3;
...
u:\CYGWIN\USR\B IN;u:\CYGWIN\US R\LOCAL\BIN;...

Another workaround is to remove the cygwin directories from PATH:
I reinstalled the cygwin tcltk and the problem reappeared,
moving the first cygwin directory to come after the python directory
did not help. Then I removed those directories completely from PATH
(during the build) and the problem disappeared again.

I would consider this as a bug (in both py2exe and Installer) since
they decide to pick some cygwin tcl/tk dll's who happen to hang around
while the Python runtime won't...


This is part of the code (in build_exe.py).

def find_dependend_ dlls(self, use_runw, dlls, pypath, dll_excludes):
import py2exe_util
sysdir = py2exe_util.get _sysdir()
windir = py2exe_util.get _windir()
# This is the tail of the path windows uses when looking for dlls
# XXX On Windows NT, the SYSTEM directory is also searched
exedir = os.path.dirname (sys.executable )
syspath = os.environ['PATH']
loadpath = ';'.join([exedir, sysdir, windir, syspath])

# Found by Duncan Booth:
# It may be possible that bin_depends needs extension modules,
# so the loadpath must be extended by our python path.
loadpath = loadpath + ';' + ';'.join(pypath )

Can you try to change the last line into

loadpath = ';'.join(pypath ) + ';' + loadpath

and report if this helps?

Thanks,

Thomas
Jul 18 '05 #6
On 30/12/2003 0:20, Thomas Heller wrote:
Luc Saffre <lu********@gmx .net> writes:
I would consider this as a bug (in both py2exe and Installer) since
they decide to pick some cygwin tcl/tk dll's who happen to hang around
while the Python runtime won't...

This is part of the code (in build_exe.py).

def find_dependend_ dlls(self, use_runw, dlls, pypath, dll_excludes):
import py2exe_util
sysdir = py2exe_util.get _sysdir()
windir = py2exe_util.get _windir()
# This is the tail of the path windows uses when looking for dlls
# XXX On Windows NT, the SYSTEM directory is also searched
exedir = os.path.dirname (sys.executable )
syspath = os.environ['PATH']
loadpath = ';'.join([exedir, sysdir, windir, syspath])

# Found by Duncan Booth:
# It may be possible that bin_depends needs extension modules,
# so the loadpath must be extended by our python path.
loadpath = loadpath + ';' + ';'.join(pypath )

Can you try to change the last line into

loadpath = ';'.join(pypath ) + ';' + loadpath

and report if this helps?


Yes, this fixed the bug. Here is my test report:

1. I reproduced the bug by running a build with cygwin's tcltk package
installed: again, some part of cygwin had been grabbed. This time
however the behaviour was that the test.exe got stucked completely,
needing to be killed using TaskManager. This difference may come because
I upgraded meanwhile my copy of Cygwin.

2. I modified the line in build_exe.py as described.

3. Now the produced .exe runs well in both cases (tcltk installed during
build or not)

Sorry for the long delay before testing this.

Luc
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2528
by: wireless200 | last post by:
I'm running EM on my local box and sql server on a remote internet accessed box. How do I specify a file path for a DTS package to access files on the remote box? For example, to run a local dts package the filepath is c:\filepath\file.txt. How would I change the file path/name to allow the dts package to
5
3945
by: Alfredo Magallón Arbizu | last post by:
Hi, I have an ASP.NET app that works perfectly in Windows Server 2003, but fails in Windows 2000. It fails when trying to read the data in an Excel Workbook (range.value)... The error is: COMException (0x80020008): Bad Variable Type
2
1908
by: David Reynolds | last post by:
Hi Everybody, I have a vb.net webform where I create the Excel application/workbook/worksheet. On Windows 2000 server for some reason, I keep getting an error("Bad variable type") when trying to first set the value to a cell. I don't have the problem on 2003 server or XP, and I'm wondering if anyone knows of a get around on 2000? Try...
1
20524
by: Geoff Cox | last post by:
Hello, I have a few hundred zip files (each one has 1 MS Word doc in it) in the c:\docs folder I run the following script and get "bad file descriptor" after the first doc file has been created from the first zip file. Any ideas why?!
3
8120
by: gazelle04 | last post by:
I wanted to create a subfolder in a directory and I used the MkDir statement but it gives me an error like "Path/File access error" Here are the codes: MkDir "\\BC123456\Attachments\" & Me.UniversityID.Value BC123456 = shared computer Attachments = shared folder Me.UniversityID = is a text box on the form with a number format
6
2294
by: Jerad Rose | last post by:
I recently installed Visual Studio 2003, after having already installed VS 2005. Unfortunately, it took over all of the file associations. There is an option in Visual Studio 2005 to restore these associations, under Tools > Options Environment General. However, this button doesn't seem to do anything. Specifically, my SLN files were...
1
14019
by: ChollaPete | last post by:
This code: <form action="processScan.php" method="get"> <p> <?php print "Scan name: <input type=\"file\" name=\"tScanFileName\" value= \"{$scanFileName}\"><br>"; addHiddenCarryons(); ?> <input type="submit">
1
2270
by: jld730 | last post by:
Hello All, I have a fairly simple script that runs fine, does what it is supposed to do, but generally on the second run (after running fine again) it throws the following error: *** Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\intpyapp.py", line 341, in OnFileRun ...
0
1220
by: bluethunder | last post by:
Good day! I'm having a problem with my program with regards in reports. I'm using VB 6, .mdb as my back end and Crystal Report 8.5 for my reports. After I input the required data and press the print button, it gives me an error of: error opening file file could not be found: "Rpt", at file location: "Rpt" I don't know why the error...
0
7611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7812
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7574
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3579
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1145
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.