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

Ubuntu20.04下Python3.5构建项目遇ImportError: No module named 'numpy'

Fixing "ImportError: No module named 'numpy'" with Python 3.5 on Ubuntu 20.04

Got it, let's work through this issue step by step. The core problem here is that numpy isn't installed for your custom Python 3.5 environment—even if it exists for your system's default Python 3.8, the two environments are completely separate. Here's how to fix this:

Step 1: Make sure Python 3.5 has its own pip

Custom Python installs sometimes don't set up pip automatically. Let's fix that first:

  • Confirm your Python 3.5 path with: which python3.5 (you’ll likely see something like /usr/local/bin/python3.5)
  • Install or upgrade pip specifically for Python 3.5:
    python3.5 -m ensurepip --upgrade
    

Step 2: Install numpy for Python 3.5 (not system Python)

Don’t use the generic pip install numpy command—it will install numpy for Python 3.8, not your 3.5 version. Instead, use Python 3.5's own pip:

python3.5 -m pip install numpy

If you hit compilation errors (since you’re using gcc-5), explicitly tell pip to use this compiler during numpy's build process:

CC=gcc-5 python3.5 -m pip install numpy

Step 3: Verify the installation

Double-check that numpy is now available for Python 3.5:

python3.5 -c "import numpy; print(numpy.__version__)"

If this prints a version number without errors, you’re ready to proceed.

Step 4: Re-run your build command

Now try executing your original command again:

python3.5 setup.py build develop

To avoid dependency conflicts between your system Python and custom Python 3.5, set up an isolated virtual environment:

  1. Install virtualenv for Python 3.5:
    python3.5 -m pip install virtualenv
    
  2. Create and activate a dedicated environment for your project:
    virtualenv -p python3.5 my_project_env
    source my_project_env/bin/activate
    
  3. Install numpy (and any other project dependencies) inside this environment, then run your setup command—this keeps everything clean and avoids cross-environment issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 10:13:16