为什么 conda 会升级 python 的版本,如何防止?
Why does conda upgrade the version of python and how can I prevent it?
我正在探索将 conda 用于我正在从事的项目。我不熟悉 conda,所以我想更好地理解它。
我正在构建一个包含 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
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
请注意,我正在安装的唯一软件包是 invoke。当我这样做时,它还安装的依赖项之一是 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
我特意选择 python3.7 因为(如下所示)debian:buster-slim
没有 python3.8 包:
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3.8
E: Couldn't find any package by glob 'python3.8'
E: Couldn't find any package by regex 'python3.8'
The command '/bin/sh -c apt update && apt install python3.8 curl python3-pip -y' returned a non-zero code: 100
为什么 conda 会升级我的 python 版本,我该如何防止这种情况发生?这不是一个大问题,我只是想了解为什么它会发生,特别是正如我假设的那样,因为没有 python3.8 包用于 debian,python3.8 是不可取的。
我不知道为什么 anaconda 在你的情况下更新 python 的版本,但我认为你可以通过键入以下命令强制你的新虚拟环境的 python 版本来阻止它:
conda create --name py37 Python==3.7
里面有详细的说明
我正在探索将 conda 用于我正在从事的项目。我不熟悉 conda,所以我想更好地理解它。
我正在构建一个包含 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
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
请注意,我正在安装的唯一软件包是 invoke。当我这样做时,它还安装的依赖项之一是 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
我特意选择 python3.7 因为(如下所示)debian:buster-slim
没有 python3.8 包:
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3.8
E: Couldn't find any package by glob 'python3.8'
E: Couldn't find any package by regex 'python3.8'
The command '/bin/sh -c apt update && apt install python3.8 curl python3-pip -y' returned a non-zero code: 100
为什么 conda 会升级我的 python 版本,我该如何防止这种情况发生?这不是一个大问题,我只是想了解为什么它会发生,特别是正如我假设的那样,因为没有 python3.8 包用于 debian,python3.8 是不可取的。
我不知道为什么 anaconda 在你的情况下更新 python 的版本,但我认为你可以通过键入以下命令强制你的新虚拟环境的 python 版本来阻止它:
conda create --name py37 Python==3.7