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

Ubuntu16.04+PyCharm2018.1.1+Python3.5下numpy导入错误求助

Fixing "ImportError: No module named 'numpy'" in PyCharm on Ubuntu

Hey there, I get how frustrating it is to hit this error even after repeating the setup dozens of times. Let's cut to the chase—this almost always boils down to a mismatch between the Python interpreter PyCharm is using and the one where you installed numpy. Let's walk through the fixes step by step:

1. Confirm PyCharm's Active Python Interpreter

First, let's make sure we know which Python version PyCharm is trying to use for your project:

  • Open your project in PyCharm.
  • Navigate to File > Settings > Project: [Your Project Name] > Python Interpreter (on macOS, it's PyCharm > Preferences > Project: [Your Project Name] > Python Interpreter).
  • Take note of the interpreter path at the top (it might look like /usr/bin/python3.10 or a path pointing to a virtual environment folder).

2. Check Where Your numpy Installation Lives

Now let's verify which Python version actually has numpy installed:

  • Open your Ubuntu terminal and run this command:
    pip3 show numpy
    
    Look for the Location line in the output—it'll tell you which Python's site-packages or dist-packages folder numpy is in (e.g., /usr/lib/python3.10/dist-packages). Compare this Python version to the one PyCharm is using. If they don't match, that's exactly why the import fails.

3. Fix the Mismatch (Two Easy Options)

Option 1: Point PyCharm to the System Python with numpy

  • Go back to PyCharm's Python Interpreter settings.
  • Click the gear icon > Add.
  • Select System Interpreter, then pick the Python path that matches where numpy is installed (you can find the exact path with which python3 in terminal).
  • Save the settings, then try importing numpy again in your project.

Option 2: Install numpy Directly in PyCharm's Interpreter

If you'd rather keep using the interpreter PyCharm has selected:

  • In the Python Interpreter settings, click the + button to add a new package.
  • Search for numpy, select it from the list, and click Install Package. PyCharm will handle installing it directly to the interpreter your project is using.

4. Double-Check for Version Confusion

  • Always use pip3 (not pip) when installing packages for Python 3—sometimes pip defaults to Python 2 on Ubuntu, which would install numpy in the wrong place. Run this to ensure numpy is up-to-date for Python 3:
    sudo pip3 install --upgrade numpy
    
  • Also, check if your project has a hidden virtual environment folder (like venv or env). If it does, PyCharm might be using that instead of the system Python—you'll need to activate the venv in terminal and install numpy there, or switch PyCharm to use the system interpreter.

Give these steps a try—this should resolve the import error once and for all.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:49:25