简体   繁体   English

使用特定的 python 版本创建 conda env,并预先下载该 python 包

[英]create conda env with specific python version, with that python package predownloaded

I'm trying to create a Conda env with a specific python version, eg,我正在尝试使用特定的 python 版本创建一个 Conda env,例如,

conda create --name my_env python=3.6

which gives:这使:

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/*/anaconda3/envs/my_env

  added / updated specs:
    - python=3.6


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    python-3.6.12              |       h26836e1_2        16.9 MB
    ------------------------------------------------------------
                                           Total:        16.9 MB

The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/osx-64::ca-certificates-2020.7.22-0
  certifi            pkgs/main/osx-64::certifi-2020.6.20-py36_0
  libcxx             pkgs/main/osx-64::libcxx-10.0.0-1
  libedit            pkgs/main/osx-64::libedit-3.1.20191231-h1de35cc_1
  libffi             pkgs/main/osx-64::libffi-3.3-hb1e8313_2
  ncurses            pkgs/main/osx-64::ncurses-6.2-h0a44026_1
  openssl            pkgs/main/osx-64::openssl-1.1.1g-h1de35cc_0
  pip                pkgs/main/osx-64::pip-20.2.2-py36_0
  python             pkgs/main/osx-64::python-3.6.12-h26836e1_2
  readline           pkgs/main/osx-64::readline-8.0-h1de35cc_0
  setuptools         pkgs/main/osx-64::setuptools-49.6.0-py36_0
  sqlite             pkgs/main/osx-64::sqlite-3.33.0-hffcf06c_0
  tk                 pkgs/main/osx-64::tk-8.6.10-hb0a8c7a_0
  wheel              pkgs/main/noarch::wheel-0.35.1-py_0
  xz                 pkgs/main/osx-64::xz-5.2.5-h1de35cc_0
  zlib               pkgs/main/osx-64::zlib-1.2.11-h1de35cc_3

But since I continue getting this error when it's trying to download the python package:但是由于我在尝试下载 python 包时继续收到此错误:

Downloading and Extracting Packages
python-3.6.12        | 16.9 MB   | ###################################################################################6                             |  75% 

CondaError: Downloaded bytes did not match Content-Length
  url: https://repo.anaconda.com/pkgs/main/osx-64/python-3.6.12-h26836e1_2.conda
  target_path: /Users/*/anaconda3/pkgs/python-3.6.12-h26836e1_2.conda
  Content-Length: 17674328
  downloaded bytes: 13207996

I decided to download the python package first via curl :我决定先通过curl下载 python 包:

curl https://repo.anaconda.com/pkgs/main/osx-64/python-3.6.12-h26836e1_2.conda --output /Users/*/anaconda3/pkgs/python-3.6.12-h26836e1_2.conda

However, when I run the create env command again, I see that it is trying the download the package package again... Is there a way to tell conda to install from the package that I already downloaded instead of downloading it again?但是,当我再次运行 create env 命令时,我看到它正在尝试再次下载包...有没有办法告诉 conda 从我已经下载的包中安装而不是再次下载? Thanks in advance!!!提前致谢!!!

The downloading failed.下载失败。 The package was not downloaded completely and broken.该软件包未完全下载并已损坏。

Cleanup the package cache and reinstall python 3.6.清理包缓存并重新安装python 3.6。

conda clean --tarballs

# if my_env is not created
conda create --name my_env python=3.6

# else if my_env has been created already
conda activate my_env
conda install python=3.6 -y

Don't try to download the python package manually.不要尝试手动下载 python 包。 Cause原因

  1. python depends on other packages (about 14 other pkgs), you have to walk the dependency tree and download every dependents one by one. python依赖于其他包(大约14个其他包),你必须遍历依赖树并一一下载每个依赖。
  2. Only put the python pkg into conda cache is not enough.仅将 python pkg 放入 conda 缓存是不够的。 Additional info is written after unpacking the .conda file.解压.conda文件后会写入附加信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM