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

无网络环境下如何从Anaconda base环境复制指定包到新环境?

Copy Specific Packages from Conda Base Environment to a New Offline Environment

Hey there! This is such a common pain point when working offline with Conda—no need to waste time copying every single package from base. Let’s break down the best methods to transfer exactly the 10-20 packages you need, no internet required.

First, Understand Conda’s Local Cache

Conda automatically stores every package you’ve ever installed (including those in base) in a local cache directory. On most systems:

  • Linux/macOS: ~/anaconda3/pkgs/
  • Windows: C:\Users\YourUsername\anaconda3\pkgs

All the .conda or .tar.bz2 files here are the installers for your base packages—we’ll leverage this instead of downloading anything new.

This is the simplest way if your target packages were installed via Conda in the base environment.

  1. List base environment packages to get versions:
    Run this to see all packages in base, note the exact version numbers for the ones you want:

    conda list -n base
    

    For example, you might see numpy 1.26.0 py311h59b608b_0—you’ll need numpy=1.26.0 for the install command.

  2. Activate your new environment:

    conda activate your-new-env-name
    
  3. Install specific packages offline:
    Use the --offline flag to force Conda to only use its local cache. List your target packages with their versions:

    conda install --offline numpy=1.26.0 pandas=2.1.3 matplotlib=3.8.0
    

    Conda will pull all these packages directly from the pkgs cache directory—no internet needed.

Method 2: Use a Package List File

If you have a long list of packages, it’s easier to create a text file with the package names and versions, then install from that.

  1. Create a required-packages.txt file:
    Add each package and its version on a new line, like this:

    numpy=1.26.0
    pandas=2.1.3
    scipy=1.11.3
    seaborn=0.13.0
    
  2. Install from the file offline:
    Activate your new environment, then run:

    conda install --offline --file required-packages.txt
    

Method 3: For Pip-Installed Packages in Base

If some of your target packages were installed via pip in base (not Conda), you can use Pip’s local cache to install them offline.

  1. Locate Pip’s cache directory:

    • Linux/macOS: ~/.cache/pip/wheels/
    • Windows: C:\Users\YourUsername\AppData\Local\pip\Cache\wheels
  2. Install from local wheels:
    Activate your new environment, then use --no-index (skip PyPI) and --find-links (point to local cache directories):

    pip install --no-index --find-links=~/anaconda3/pkgs --find-links=~/.cache/pip/wheels numpy pandas
    

    This tells Pip to look for package wheels in both Conda’s cache and its own local cache.

Quick Note: There’s No --use-locals Flag, But...

You’re right that there’s no exact --use-locals parameter for Conda, but the --offline flag achieves exactly what you want—it restricts Conda to only use packages already present on your machine.

Troubleshooting Tip

If a package isn’t found in the cache, it’s likely that the base environment’s version was compiled from source (not downloaded as a pre-built package). In that case, you’d need to manually copy the package’s files from base/lib/pythonX.X/site-packages/ to your new environment’s site-packages/ directory, but this is rare for most common packages.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:52:54