You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置PyCharm使其识别已安装的系统Python库?

Fixing PyCharm's "ModuleNotFoundError" for System-Installed Python Libraries

Hey there! I totally get this confusion—PyCharm's default setup uses isolated virtual environments for each project, which is great for dependency management but can trip up new users when they want to use libraries installed globally via pip. Let's get this sorted step by step:

Why This Happens

When you run python main.py in your macOS terminal, you're using your system-wide Python interpreter (the one where you installed matplotlib/numpy via pip). But PyCharm automatically creates a separate virtual environment for each new project by default—this environment doesn't have access to the libraries you installed globally. That's why you're seeing the ModuleNotFoundError.

Step 1: Access PyCharm's Interpreter Settings

First, open the settings menu:

  • On macOS: Go to PyCharm → Settings (or use the shortcut Cmd + ,)
  • On Windows/Linux: Go to File → Settings (shortcut Ctrl + Alt + S)

In the settings window, navigate to Project: [Your Project Name] → Python Interpreter. Click the gear icon in the top-right corner and select Add.

Step 2: Select Your System-Wide Python Interpreter

In the pop-up window:

  1. Switch to the System Interpreter tab.
  2. Find the Python interpreter you use in your terminal. On macOS, this is often:
    • /usr/bin/python3 (the default system Python)
    • Or a version-specific path like /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 (if you installed Python via the official installer)
      Pro tip: Run which python or which python3 in your terminal to get the exact path of your system interpreter.
  3. Once you select the correct interpreter, you'll see a list of all libraries installed globally (including matplotlib and numpy) in the pane below. Click OK to confirm.

Step 3: Set This Interpreter as the Global Default (For All Projects)

If you want every new PyCharm project to use your system interpreter by default (so you don't have to repeat this setup):

  1. Go back to the Python Interpreter settings page, click the gear icon again, and select Show All.
  2. In the list of available interpreters, select the system interpreter you just added.
  3. Click the star icon in the top-right corner of this window—this marks it as the default interpreter for all future projects.
  4. Alternatively, go to File → New Project Settings → Settings for New Projects, then select the system interpreter under Python Interpreter.

Verify the Fix

After setting this up:

  • Run your test code again in PyCharm—it should now load matplotlib and numpy without errors and display the plot.
  • You can also open PyCharm's built-in terminal (bottom toolbar) and run pip list—you should see the same libraries listed as when you run the command in your system terminal.

内容的提问来源于stack exchange,提问作者jnemecz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 01:44:09