Danny
Danny

Reputation: 780

Python 2.7: "unresolved import: ConfigParser"

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.

Upvotes: 2

Views: 2175

Answers (2)

jspencer
jspencer

Reputation: 532

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

Upvotes: 6

Fabio Zadrozny
Fabio Zadrozny

Reputation: 25332

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).

Upvotes: 0

Related Questions