2

I recently wrote a Python 2.7 script (using PyDev on Eclipse) that took advantage of the built-in ConfigParser module, and the script works perfectly. But when I exported it and sent it to a colleague, he could not get it to work. He keeps getting an "unresolved import: ConfigParser" error even though we are using the exact same settings. This isn't supposed to happen as ConfigParser is built-in.

I've Googled everywhere but could not seem to find any working solution. Any help would be appreciated.

Danny
  • 705
  • 1
  • 7
  • 23
  • I assume PyDev gives this complaint but the code runs fine? –  Aug 28 '12 at 16:50
  • 6
    What version of Python is your colleague using? In Python 3.x, the module has been renamed to ``configparser``. – Ned Deily Aug 28 '12 at 16:51
  • Delnan: The code doesn't run on his computer. Ned Deily: We're both using 2.7. – Danny Aug 28 '12 at 17:02
  • Then what is the exception he gets when running it? Because "unresolve import: ..." is a PyDev message, not an error. –  Aug 28 '12 at 17:03
  • I just checked with him - it doesn't recognize the module. – Danny Aug 28 '12 at 20:54
  • related: [Unresolved Import Issues with PyDev and Eclipse](http://stackoverflow.com/questions/4631377/unresolved-import-issues-with-pydev-and-eclipse) – jfs Aug 28 '12 at 22:53

2 Answers2

6

ConfigParser was renamed to configparser in python 3. Chances are he's using 3 and cannot find the old py2 name.

You can use:

try:
    import configparser as ConfigParser
except ImportError:
    import ConfigParser
jspencer
  • 522
  • 4
  • 14
0

To see what's happening it may be nice comparing on both computers which sys.path is being used (i.e.: put at the start of the module being run the code below and compare the output in each case):

import sys
print '\n'.join(sorted(sys.path))

Now, if the error is not when running the code (i.e.: it runs fine and you get no exceptions), and he gets the error only in PyDev, probably the interpreter configuration in his side is not correct and one of the paths printed through the command above is not being added to the PYTHONPATH (it could be that he's on a virtual env and didn't add the paths to the original /Lib or has added some path that shouldn't be there -- or even has some ConfigParser module somewhere else which is conflicting with the one from the Python standard library).

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78