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

Ubuntu22 EC2实例中Mamba创建环境停滞,本地运行正常

在AWS EC2 Ubuntu 22实例上部署Python应用时Mamba环境创建停滞的排查方案

问题背景

本地执行mamba env create --file=environment.yml可正常创建虚拟环境并运行Python Web应用,但在新AWS EC2 Ubuntu 22实例上,该命令输出Looking for: ['python=3.11', 'langchain', 'openai', 'tiktoken', 'pandas', 'streamlit', 'pip']后停滞约5秒无进展,需排查问题根源。

已执行操作

# 下载并安装mamba 
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
bash Mambaforge-$(uname)-$(uname -m).sh
git clone https://github.com/username/repo
mamba env create --file=environment.yml

environment.yml配置

name: environment-name
channels:
  - conda-forge
  - nodefaults
dependencies:
  - python=3.11
  - langchain
  - openai
  - tiktoken
  - pandas
  - streamlit
  - pip

  - pip:
    - streamlit-authenticator

排查与解决步骤

1. 检查网络连通性

EC2实例可能因网络限制无法访问conda-forge源:

  • 执行ping conda-forge.org测试连通性,超时则说明网络存在问题
  • 检查EC2安全组规则,确保出站流量允许HTTPS(443端口)访问公网
  • 若实例在私有子网,确认NAT网关配置正常,可转发出站请求

2. 启用详细日志定位停滞环节

添加-vvv参数查看Mamba执行细节,明确是卡在包索引下载还是依赖解析阶段:

mamba env create --file=environment.yml -vvv

3. 更换conda-forge镜像源

默认源在AWS区域可能访问缓慢,替换为国内镜像源:
编辑~/.condarc文件,内容修改为:

channels:
  - conda-forge
  - nodefaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

保存后重新执行环境创建命令。

4. 检查实例资源占用

低规格EC2实例(如t2.micro)可能因CPU/内存不足导致依赖解析停滞:

  • 执行top查看资源占用,若CPU或内存使用率接近100%,升级实例规格后重试
  • 临时关闭其他占用资源的进程,释放资源后再尝试创建环境

5. 重新安装Mambaforge确保完整性

重新执行静默安装,避免交互式步骤的配置遗漏:

rm -rf Mambaforge-*.sh
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
bash Mambaforge-$(uname)-$(uname -m).sh -b -p $HOME/mambaforge
source $HOME/mambaforge/bin/activate

6. 分步安装依赖定位问题包

先创建基础Python环境,再逐个添加依赖,确认是否为特定包导致的停滞:

mamba create -n test-env python=3.11
mamba activate test-env
mamba install langchain openai tiktoken pandas streamlit pip
pip install streamlit-authenticator

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 14:22:17