Python控制台出现“no module named”错误:已安装模块仍无法导入
Fixing "ModuleNotFoundError" for requests/numpy in PyCharm
Hey there, I’ve run into this exact head-scratcher before—9 times out of 10, it’s because PyCharm is using a different Python interpreter than the one you installed your packages with. Let’s work through the fixes step by step:
Step 1: Check which interpreter PyCharm is using
- Open PyCharm, go to File > Settings (Windows/Linux) or PyCharm > Preferences (Mac).
- Navigate to Project: [Your Project Name] > Python Interpreter.
- Scan the list of installed packages here. If
requestsandnumpyaren’t listed, that confirms PyCharm’s interpreter doesn’t have them installed.
Step 2: Verify your system pip’s Python version
- Open your system’s terminal (not PyCharm’s built-in console) and run:
pip --version - This will show you which Python installation your
pipis linked to (e.g.,pip 23.3.1 from C:\Python311\Lib\site-packages\pip (python 3.11)). Compare this path to the one shown in PyCharm’s Python Interpreter settings—if they don’t match, that’s the root cause.
Step 3: Fix the issue with one of these methods
Method 1: Install packages directly in PyCharm
- Stay in the Python Interpreter settings page.
- Click the
+button in the top-right corner. - Search for
requestsandnumpyone by one, select them, then click Install Package. Wait for the installation to finish, then try importing again in the PyCharm console.
Method 2: Switch PyCharm’s interpreter to match your system pip
- In the Python Interpreter settings page, click the dropdown menu at the top and select Show All.
- Click the
+button, then choose System Interpreter. - Browse to the Python path you saw from
pip --version(e.g.,C:\Python311\python.exe), select it, and click OK. - Set this interpreter as the default for your project, then restart PyCharm and test the imports.
Bonus: If you’re using a virtual environment
- If you created a virtual environment for your project, make sure you’re activating it in your terminal before running
pip install requests numpy. Or, in PyCharm’s interpreter settings, select your virtual environment’s Python executable instead of the system one.
内容的提问来源于stack exchange,提问作者Julio Sca
相关产品推荐
相关产品推荐

