Python3.6+Conda虚拟环境中configparser模块存在却无法调用的问题
ImportError: No module named configparser in Conda + PyCharm (Python 3.6) Hey there! I’ve run into this exact issue before with Conda environments in PyCharm, so let’s walk through the fixes step by step:
Double-check your PyCharm interpreter configuration
PyCharm sometimes defaults to the system Python instead of your Conda virtual environment. Here’s how to verify:- Go to
File > Settings(orPyCharm > Settingson macOS) - Navigate to
Project: [Your Project Name] > Python Interpreter - Look at the interpreter path—it should point to your Conda env’s Python executable, like
~/miniconda3/envs/your-env/bin/python(Linux/macOS) orC:\Users\You\miniconda3\envs\your-env\python.exe(Windows) - If it’s wrong, click the gear icon >
Add > Conda Environment > Existing environment, select the correct path, then hitApply
- Go to
Reinstall configparser in your Conda env
Even though Python 3.6 ships withconfigparserby default, environment corruption can break this. Open PyCharm’s built-in Terminal (make sure you see(your-env)at the start of the prompt) and run:pip install --force-reinstall configparserOr if you prefer using Conda:
conda install -c anaconda configparser --force-reinstallVerify your import statement
Don’t overlook the basics! In Python 3, the module is lowercase:import configparser # Correct for Python 3If you accidentally used the Python 2 syntax (
import ConfigParser), that’ll throw the error immediately.Clear PyCharm’s cache and restart
PyCharm’s cache can sometimes get stuck and fail to recognize installed modules. Fix this by:- Clicking
File > Invalidate Caches... - Checking the box for "Invalidate and Restart"
- Letting PyCharm restart and reindex your project
- Clicking
One of these steps should get configparser working for you!
内容的提问来源于stack exchange,提问作者Caesar Khaled Alsaih

