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

Ubuntu环境下安装TensorFlow CPU版创建Virtualenv报错求助

Hey there! Let's figure out what's going wrong here. The command you ran mixes two separate operations—installing packages via apt-get and creating a virtual environment with virtualenv—which is why you're hitting an error. Let's break this down into correct, actionable steps:

Step 1: Install Required Packages First

First, run the apt-get command without the virtualenv-specific flags (--system-site-packages and -p), since those don't belong to the package installation process. Also, python-virtualenv is deprecated in newer Ubuntu releases, so we only need virtualenv:

sudo apt-get update && sudo apt-get install python3-pip python3-dev virtualenv -y
Step 2: Create Your Virtual Environment

Now that the tools are installed, use the virtualenv command to set up your environment in the target directory. The -p flag specifies which Python interpreter to use, and --system-site-packages lets the environment access system-wide installed packages:

virtualenv --system-site-packages -p python3 /home/ubuntu/workspace/tensor/

Note: If the /home/ubuntu/workspace/ directory doesn't exist yet, create it first with:

mkdir -p /home/ubuntu/workspace/
Step 3: Activate the Environment & Install TensorFlow CPU

Once the environment is created, activate it—your terminal prompt will show (tensor) to confirm you're in the right context:

source /home/ubuntu/workspace/tensor/bin/activate

Now install the TensorFlow CPU version. For newer TensorFlow 2.x releases, the main tensorflow package automatically defaults to CPU mode if no GPU is detected, so you can use either of these commands:

# Option 1: Explicit CPU package
pip install tensorflow-cpu

# Option 2: Main package (auto-detects no GPU)
pip install tensorflow
Troubleshooting Common Issues
  • Permission Errors: If you run into permission issues when creating the environment, don't use sudo with virtualenv—your user should have write access to the /home/ubuntu/workspace/ directory. If you accidentally used sudo earlier, fix the ownership with:
    sudo chown -R ubuntu:ubuntu /home/ubuntu/workspace/tensor/
    
  • Pip Upgrade Errors: If pip throws installation errors, upgrade it first inside the activated environment:
    pip install --upgrade pip
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:50:31