Could someone explain this lovely little behavior of Python to me? When running Python interactively, I'll be able to import any given module;
>>> import xml.parsers.expat
>>> import wxPython.wx
>>>
Then, when I try to run a script with these import
commands, Python can't find those modules. So I go back to the interactive session with Python, and suddenly I can't import the same modules there either.
>>> import xml.parsers.expat
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/Users/Albright/xml.py", line 3, in ?
import xml.parsers.expat
ImportError: No module named parsers.expat
>>> import wxPython.wx
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "//Library/Python/2.3/wx-2.5.3-mac-unicode/wxPython/__init__.py", line 10, in ?
import _wx
File "//Library/Python/2.3/wx-2.5.3-mac-unicode/wxPython/_wx.py", line 3, in ?
from _core import *
File "//Library/Python/2.3/wx-2.5.3-mac-unicode/wxPython/_core.py", line 15, in ?
import wx._core
File "/Users/Albright/wx.py", line 2, in ?
from wxPython.wx import *
ImportError: No module named wx
>>>
Nothing I've found will let me get those modules back. What's the deal? :(
Found a bit of a workaround... If I copy that xml.parsers.expat
module from the directory where modules are stored into the same directory the script is stored or I run the Python CLI from, I can import it. I shouldn't have to do this, though, and I haven't found out how to replicate this workaround with wxPython, which I'd also like to use.
Fucking Python. I wish I could do GUI programs with PHP. For as long as Python has been around, it seems really immature at times...
/me investigates Ruby
So many languages, so little time...
Have I mentioned I'm a dumbass recently?
The reasons both of these were failing is because my test scripts were named xml.py
and wx.py
, and they were both in ~
, where I was running Python from more often than not. So Python was trying to import those instead of the correct modules. It was behaving correctly. (I was to the point where I was machine-translating messages from the Chinese Python mailing list before this occurred to me.)
So it turned out to be a ID-10-T error the whole time. Sorry for starting a thread about this.... Gyaah.