472,358 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

"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 3795
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\PaletteFile.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\ImageChops.py to PIL\ImageChops.pyc
skipping byte-compilation of C:\PYTHON23\lib\StringIO.py to StringIO.pyc
byte-compiling
T:\data\luc\release\lino\tests\py2exe\build\bdist. win32\winexe\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.py to
dummy_thread.pyc
byte-compiling
T:\data\luc\release\lino\tests\py2exe\build\bdist. win32\winexe\temp\PIL._imaging.py
to PIL\_imaging.pyc
skipping byte-compilation of
C:\PYTHON23\lib\site-packages\PIL\ImageFilter.py to PIL\ImageFilter.pyc
skipping byte-compilation of
C:\PYTHON23\lib\site-packages\PIL\GimpGradientFile.py to
PIL\GimpGradientFile.pyc
skipping byte-compilation of
C:\PYTHON23\lib\site-packages\PIL\__init__.py to PIL\__init__.pyc
skipping byte-compilation of C:\PYTHON23\lib\posixpath.py to posixpath.pyc
byte-compiling
T:\data\luc\release\lino\tests\py2exe\build\bdist. win32\winexe\temp\_tkinter.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\GimpPaletteFile.py to
PIL\GimpPaletteFile.pyc
skipping byte-compilation of C:\PYTHON23\lib\sre_constants.py to
sre_constants.pyc
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\ImagePalette.py to PIL\ImagePalette.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\Image.py
to PIL\Image.pyc
skipping byte-compilation of C:\PYTHON23\lib\repr.py to repr.pyc
byte-compiling
T:\data\luc\release\lino\tests\py2exe\build\bdist. win32\winexe\temp\PIL._imagingtk.py
to PIL\_imagingtk.pyc
skipping byte-compilation of
C:\PYTHON23\lib\site-packages\PIL\ImageTk.py to PIL\ImageTk.pyc
skipping byte-compilation of
C:\PYTHON23\lib\site-packages\PIL\ImageTransform.py to
PIL\ImageTransform.pyc
skipping byte-compilation of C:\PYTHON23\lib\copy.py to copy.pyc
skipping byte-compilation of
C:\PYTHON23\lib\site-packages\PIL\ImageColor.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\DLLs\_sre.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\lib\site-packages\PIL\_imaging.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\DLLs\_tkinter.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\lib\site-packages\PIL\_imagingtk.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
*** copy dlls ***
copying u:\CYGWIN\BIN\cygwin1.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying u:\CYGWIN\BIN\tk84.dll -> T:\data\luc\release\lino\tests\py2exe\dist
copying C:\WINNT\System32\python23.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\DLLs\tcl84.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying u:\CYGWIN\BIN\tcl84.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\lib\site-packages\py2exe\run.exe ->
T:\data\luc\release\lino\tests\py2exe\dist\test.ex e
copying C:\PYTHON23\lib\site-packages\py2exe\run_w.exe ->
T:\data\luc\release\lino\tests\py2exe\dist\tkhello .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\DLLs\_sre.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\lib\site-packages\PIL\_imaging.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\DLLs\_tkinter.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\lib\site-packages\PIL\_imagingtk.pyd ->
T:\data\luc\release\lino\tests\py2exe\dist
*** copy dlls ***
I guess the problem is here:
copying u:\CYGWIN\BIN\cygwin1.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying u:\CYGWIN\BIN\tk84.dll -> T:\data\luc\release\lino\tests\py2exe\dist
copying C:\WINNT\System32\python23.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\DLLs\tcl84.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying u:\CYGWIN\BIN\tcl84.dll ->
T:\data\luc\release\lino\tests\py2exe\dist
copying C:\PYTHON23\lib\site-packages\py2exe\run.exe ->
T:\data\luc\release\lino\tests\py2exe\dist\test.ex e
copying C:\PYTHON23\lib\site-packages\py2exe\run_w.exe ->
T:\data\luc\release\lino\tests\py2exe\dist\tkhello .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\Scripts;c:\python23;
....
u:\CYGWIN\USR\BIN;u:\CYGWIN\USR\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\Scripts;c:\python23;
...
u:\CYGWIN\USR\BIN;u:\CYGWIN\USR\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\Scripts;c:\python23;
...
u:\CYGWIN\USR\BIN;u:\CYGWIN\USR\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
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...
5
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: ...
2
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...
1
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...
3
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\" &...
6
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...
1
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(); ?>...
1
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...
0
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.