简体   繁体   中英

Python 3.x ImportError: No module named configparser , but module is installed

In my code i am using configparser. Everything working fine, but after i do fresh install of windows 10, this error appears: ImportError: No module named configparser .

  • But same code working on other pc
  • Python is in PATH (double checked)
  • Try reinstall python
  • configparser is installed by default, but still try "pip install configparser"

I am using Python 3.7.1 In same code i do " import os " and this is working. Configparser is in same directory.

EDIT:

configparser is here:

c:\Program Files\Python37\Lib\configparser.py

after pip install configparser , there is another:

c:\Program Files\Python37\Lib\site-packages\backports\configparser\__init__.py

EDIT_2:

Try copy:

c:\Program Files\Python37\Lib\configparser.py

to my working folder. Result:

Traceback (most recent call last):
File "C:\git\silixcon_lib\production_data.py", line 4, in <module>
import configparser
File "C:\git\silixcon_lib\configparser.py", line 434
option, section, rawval, var) from None
                                 ^
SyntaxError: invalid syntax

This is working:

Copy this to my working folder:

c:\Program Files\Python37\Lib\site-packages\backports\configparser\__init__.py

and rename it to configparser.py. At lines 138-140 change "backports.configparser.helpers" to "helpers"

and this copy too:

c:\Program Files\Python37\Lib\site-packages\backports\configparser\helpers.py

Found cause

During instalation Platformio-ide to Atom editor, python 2.7 was installed. Python 3.7 was in path and when i run:

python -V

I see my python 3.7 version. Bud when i run python script it starts in python 2.7.

But this:

python my_script.py

starts python 3.7.

So problem is in association .py file extension. But for unknown reason a can not change .py to run in python 3.7. So for now i uninstall platformio and everything starts working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM