Ticket #336 (closed Defect: fixed)
On computers that have PYTHONCASEOK environment variable defined, MGET tools fail with ImportError: No module named config
| Reported by: | jjr8 | Owned by: | jjr8 |
|---|---|---|---|
| Priority: | Medium | Milestone: | 0.7 |
| Component: | Core - Other | Version: | |
| Keywords: | Cc: |
Description
From ArcGIS 9.3, the error looks like this:
<type 'exceptions.ImportError'>: No module named config>
A full traceback, if you are able to obtain one, is similar to this:
Traceback (most recent call last):
File "<string>", line 29, in <module>
File "C:\Python25\lib\site-packages\GeoEco\logging.py", line 22, in <module>
import logging
File "C:\Python25\lib\site-packages\GeoEco\logging.py", line 23, in <module>
import logging.config
ImportError: No module named config
The problem is that, when the PYTHONCASEOK environment variable is defined, Python searches for modules in a case-insensitive manner. See PEP 235 for more info. When MGET's GeoEco.Logging module (implemented in Logging.py) tries to import Python's own logging.config module, Python says "Oh, in this case, the logging module actually refers to GeoEco.Logging, not the logging that comes with Python", and then attempts to import GeoEco.logging.config and then fails because it does not exist.
It is rare for Python-savvy users to define PYTHONCASEOK. Certainly skilled developers will use proper case when writing their import statements, since everything else about Python is case-sensitive. So far, the only case of PYTHONCASEOK that I've come across is on certain models of IBM Thinkpads, that have Python 2.2. in the directory C:\IBMTOOOLS. I do not know why IBM thought it necessary to define PYTHONCASEOK. There are reports on the Internet of it screwing up other Python projects, in addition to MGET.
Two solutions are immediately apparent:
- Rename all GeoEco modules that have the same case-insensitive names as modules that come with Python. This includes GeoEco.Logging, GeoEco.Types, and maybe more. GeoEco.Logging would have to become GeoEco.MyLogging or something like that.
- Change MGET setup so that it refuses to install if PYTHONCASEOK is defined.
For now, I am going with solution 2. I will work with people privately to fix their machines. If you come across this problem, basically you need to remove the PYTHONCASEOK enviornment variable using Control Panel --> System, reboot, and then install MGET.
Thanks to Steve Intelmann for helping with the diagnosis of this problem.
