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

EC2实例中Python3环境pip安装报错及pip缺失问题求助

Hey there, let's work through your two issues step by step:

Fixing EC2 Python Virtual Env & Pip Problems

1. Resolving "Network is unreachable" when using pip in virtualenv

This error almost always ties back to EC2's network restrictions. Here's what to check and fix:

  • Security Group Outbound Rules: Jump into the EC2 console, locate your instance's security group, and confirm the outbound rules allow traffic to 0.0.0.0/0 on ports 80 (HTTP) and 443 (HTTPS). Some default security groups lock down outbound traffic, which blocks pip from connecting to PyPI servers.
  • Test Basic Network Connectivity: Run curl https://pypi.org in your instance's terminal. If this fails, double-check your subnet's route table—make sure it's linked to an internet gateway. If you're using a private subnet, you'll need a NAT gateway configured to access the public internet.
  • Check Proxy Settings: If your environment uses a proxy, verify pip isn't picking up incorrect proxy configs. After activating your virtualenv, run pip config list to see if there's an unwanted proxy entry. Remove it with pip config unset global.proxy if needed.

2. Fixing "/usr/bin/python3: No module named pip"

Since you manually installed Python 3.5.1 on an EC2 instance that defaults to Python 2.7, pip3 wasn't included automatically. Here's how to install it:

For Amazon Linux/CentOS-based instances:

  • First, install required system dependencies:
    sudo yum install -y python3-devel
    
  • Download the legacy pip bootstrap script compatible with Python 3.5 (note: Python 3.5 is end-of-life, so we need the specific version of the script):
    curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
    
  • Install pip3 for your system-wide Python 3:
    sudo python3 get-pip.py
    
  • Verify the installation worked:
    python3 -m pip --version
    

Now you should be able to run sudo python3 -m pip install Flask without errors.

Quick Virtualenv Best Practice

After creating your virtualenv with virtualenv -p python3 .env, don't forget to activate it first:

source .env/bin/activate

Once activated, use pip (not pip3)—the virtualenv's pip is already linked to your Python 3 installation. Then run pip install -r requirements.txt once your network issues are sorted.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:03:09