[Python-bugs-list] [ python-Bugs-619713 ] Import fails in Idle

noreply@sourceforge.net noreply@sourceforge.net
Mon, 14 Oct 2002 06:15:59 -0700


Bugs item #619713, was opened at 2002-10-07 10:15
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=619713&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Leslie Brooks (lesliebrooks)
Assigned to: Nobody/Anonymous (nobody)
Summary: Import fails in Idle

Initial Comment:
The import command works in the command line
interpreter, but fails in Idle:

>>> os.listdir('.')
['Debug', 'example.cxx', 'example.dsp', 'example.h',
'example.i', 'example.ncb', 'example.py',
'example.pyc', 'example.sln', 'example.suo',
'example.vcproj', 'example_wrap.cxx', 'foo',
'index.html', 'Makefile', 'runme.py', '_example.dll',
'_example.ilk']
>>> import _example
Traceback (most recent call last):
  File "<pyshell#16>", line 1, in ?
    import _example
ImportError: No module named _example
>>> 

     I have gotten it to work _once_ in Idle, but was
never able to repeat it.

     I am running Python 2.2.1 under Win2K (5.00.2195 SP3).


----------------------------------------------------------------------

>Comment By: Leslie Brooks (lesliebrooks)
Date: 2002-10-14 09:15

Message:
Logged In: YES 
user_id=271417

> Date: 2002-10-13 09:02
> Sender: jepler
> Logged In: YES 
> user_id=2772
> 
> Don't shared modules need the extension .pyd instead of .dll?
> 

No, I am able to load the .dll from the command line version
of Python.
Also:
   >>> imp.get_suffixes()
   [('.pyd', 'rb', 3), ('.dll', 'rb', 3), ('.py', 'r', 1),
('.pyw', 'r', 1), ('.pyc', 'rb', 2)]
shows that Python is searching for DLLs.

> Is sys.path[0] some absolute directory (the one containing
> idle.py, for instance) instead of '.'?
> 

Ahh, that is the true problem.  sys.path in Idle is:
   >>> sys.path
   ['C:\PROGRA~1\Python22\Tools\idle',
'C:\PROGRA~1\Python22', 'C:\Program
Files\Python22\DLLs', 'C:\Program 
   Files\Python22\lib', 'C:\Program
Files\Python22\lib\lib-tk', 'C:\Program
Files\Python22', 'C:\Program Files
   \Python22\lib\site-packages']
while sys.path in the command line interpreter is:
   >>> sys.path
   ['', 'C:\PROGRA~1\Python22', 'C:\Program
Files\Python22\DLLs', 'C:\Program Files\Python22\lib',
'C:\Program
   Files\Python22\lib\lib-tk', 'C:\Program
Files\Python22', 'C:\Program
Files\Python22\lib\site-packages']

So the correct title for this bug report should be "Idle
replaces sys.path[0] rather than appending a new entry to
the list".  This means that programs that work when run
through the command-line interpreter may break quite
dramatically when run from Idle, and vice versa.  

Leslie


----------------------------------------------------------------------

Comment By: Jeff Epler (jepler)
Date: 2002-10-13 09:02

Message:
Logged In: YES 
user_id=2772

Don't shared modules need the extension .pyd instead of .dll?

Is sys.path[0] some absolute directory (the one containing
idle.py, for instance) instead of '.'?

Is there a way to run idle with -v so that it lists
directories and files it tries to import as modules?

----------------------------------------------------------------------

Comment By: Leslie Brooks (lesliebrooks)
Date: 2002-10-07 17:53

Message:
Logged In: YES 
user_id=271417

     I should have noted that 'import' _does_ work to a
degree - 'import os' worked.

     The '_example.dll' that I am trying to import is the
'shapes' example that is distributed with SWIG 1.3.15, and
should import without any trouble.  It does import just fine
from the command line version of Python, but not from Idle.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=619713&group_id=5470