简体   繁体   English

为什么conda会升级python的版本,如何防止?

[英]Why does conda upgrade the version of python and how can I prevent it?

I am exploring using conda for a project I'm working on.我正在探索将 conda 用于我正在从事的项目。 I'm unfamiliar with conda so am trying to understand it a little better.我不熟悉 conda,所以我想更好地理解它。

I am building a docker image containing conda, here's what I have so far:我正在构建一个包含 conda 的 docker 图像,这是我目前所拥有的:

FROM debian:buster-slim

RUN apt update && apt install python3.7 curl python3-pip -y

RUN ln -s /usr/bin/python3.7 /usr/bin/python

# Instructions for installing miniconda https://docs.conda.io/projects/conda/en/latest/user-guide/install/rpm-debian.html?highlight=docker#rpm-and-debian-repositories-for-miniconda
RUN curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > conda.gpg && \
        install -o root -g root -m 644 conda.gpg /usr/share/keyrings/conda-archive-keyring.gpg && \
        gpg --keyring /usr/share/keyrings/conda-archive-keyring.gpg --no-default-keyring \
        --fingerprint 34161F5BF5EB1D4BFBBB8F0A8AEB4F8B29D82806 && \
        echo "deb [arch=amd64 signed-by=/usr/share/keyrings/conda-archive-keyring.gpg] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" \
        > /etc/apt/sources.list.d/conda.list

ENV MINICONDA_VERSION=4.9.2
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"

# gotten from here https://stackoverflow.com/a/58269633/201657
RUN curl -sSLO https://repo.anaconda.com/miniconda/Miniconda3-py37_${MINICONDA_VERSION}-Linux-x86_64.sh \
        # && mkdir /root/.conda \
        && bash Miniconda3-py37_${MINICONDA_VERSION}-Linux-x86_64.sh -b \
        && conda init bash 

RUN . /root/.bashrc \
        && conda create --name py37 \
        && conda activate py37 \
        && conda install invoke \
        && conda clean --all

Notice that the only package I am installing is invoke.请注意,我正在安装的唯一 package 是 invoke。 When I do so one of the dependencies that it also installs is python3.8:当我这样做时,它还安装的依赖项之一是 python3.8:

> docker run -it base
(base) root@d74295a5bbf2:/# conda activate py37
(py37) root@d74295a5bbf2:/# conda env export
name: py37
channels:
  - defaults
dependencies:
  - _libgcc_mutex=0.1=main
  - ca-certificates=2020.10.14=0
  - certifi=2020.11.8=py38h06a4308_0
  - invoke=1.4.1=py38_0
  - ld_impl_linux-64=2.33.1=h53a641e_7
  - libedit=3.1.20191231=h14c3975_1
  - libffi=3.3=he6710b0_2
  - libgcc-ng=9.1.0=hdf63c60_0
  - libstdcxx-ng=9.1.0=hdf63c60_0
  - ncurses=6.2=he6710b0_1
  - openssl=1.1.1h=h7b6447c_0
  - pip=20.3=py38h06a4308_0
  - python=3.8.5=h7579374_1
  - readline=8.0=h7b6447c_0
  - setuptools=50.3.2=py38h06a4308_2
  - sqlite=3.33.0=h62c20be_0
  - tk=8.6.10=hbc83047_0
  - wheel=0.36.0=pyhd3eb1b0_0
  - xz=5.2.5=h7b6447c_0
  - zlib=1.2.11=h7b6447c_3
prefix: /root/miniconda3/envs/py37
(py37) root@d74295a5bbf2:/# python --version
Python 3.8.5

I deliberately went with python3.7 because (as you can see below) there is no python3.8 package for debian:buster-slim :我故意使用 python3.7 因为(如下所示)没有 python3.8 package for debian:buster-slim

Reading package lists...读取 package 列表...
Building dependency tree...构建依赖树...
Reading state information...读取state信息...
E: Unable to locate package python3.8 E: 无法定位 package python3.8
E: Couldn't find any package by glob 'python3.8' E: 无法通过 glob 'python3.8' 找到任何 package
E: Couldn't find any package by regex 'python3.8' E: 无法通过正则表达式“python3.8”找到任何 package
The command '/bin/sh -c apt update && apt install python3.8 curl python3-pip -y' returned a non-zero code: 100命令“/bin/sh -c apt update && apt install python3.8 curl python3-pip -y”返回了一个非零代码:100

Why is conda upgrading my version of python and how can I prevent that from happening?为什么 conda 升级我的 python 版本,我该如何防止这种情况发生? Its not a huge problem as such, I just want to understand why its happening especially as I'm assuming, given there is no python3.8 package for debian, python3.8 is not advisable.这不是一个大问题,我只是想了解为什么会发生这种情况,特别是正如我所假设的那样,鉴于 debian 没有 python3.8 package,python3.8 是不可取的。

I don't know why anaconda is updating the version of python in your case, but I think you can prevent it by forcing the python version of your new virtual environment by typing:我不知道为什么 anaconda 在你的情况下更新 python 的版本,但我认为你可以通过键入以下内容强制你的新虚拟环境的 python 版本来防止它:

conda create --name py37 Python==3.7

There is a detailed description about it in the anaconda documentation anaconda文档中有详细说明

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

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