使用特定的 Miniconda Python 和 NumPy 版本进行 CircleCI 测试

我正在开发一个使用 CircleCI 持续集成平台的项目。我使用 Python 作为主要语言,使用 Miniconda 作为平台。我想在 CircleCI 上使用 Miniconda 测试多个 Python 和 NumPy 版本。


我尝试使用不同的 Python 映像,但在我安装最新的 Miniconda 版本时它只使用 Python 3.7。你能告诉我如何使用多个版本吗?


下面是config.yml:


version: 2.0

workflows:

  version: 2

  test:

    jobs:

      - py3.6-np1.15

      - py3.5-np1.15

      - py3.6-np1.14

      - py3.5-np1.14

      - py3.7-np1.15

      - py3.5-np1.16

      - py3.6-np1.16

      - py3.7-np1.16


jobs:

  py3.6-np1.15: &test-template

    docker:

      - image: circleci/python:3.6.8

    environment:

      NUMPY_VERSION: 1.15.2

      CYTHON_VERSION: 0.29.2

    working_directory: ~/repo


    steps:

      - checkout

      - run:

          name: Install System Dependencies

          command: sudo apt-get update && sudo apt-get install -y libmpich12 libmpich-dev build-essential


      # Download and cache dependencies

      - restore_cache:

          keys:

            - v1-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}


      - run:

          name: install anaconda

          command: |

            wget https://repo.continuum.io/miniconda/Miniconda3-4.7.10-Linux-x86_64.sh -O ~/miniconda.sh

            chmod +x ~/miniconda.sh && ~/miniconda.sh -b

            export PATH=$HOME/miniconda3/bin:$PATH

            conda update --quiet --yes conda


      - run:

          name: Install numpy, cython, mdtraj

          command: |

            export PATH=$HOME/miniconda3/bin:$PATH

            conda install --quiet --yes numpy==$NUMPY_VERSION cython==$CYTHON_VERSION

            conda install --quiet --yes -c conda-forge mdtraj


      # - run:

      #     name: Upgrade pip

      #     command: |

      #       python3 -m venv venv

      #       . venv/bin/activate

      #       pip install pip==18.0


      # - run:

      #     name: Install numpy and cython

      #     command: |

      #       python3 -m venv venv

      #       . venv/bin/activate

      #       pip install --progress-bar off numpy==$NUMPY_VERSION cython==$CYTHON_VERSION

哔哔one
浏览 243回答 1
1回答

蓝山帝景

这是一个关于如何将 CircleCI 与 Miniconda 以及特定的 Python 和 NumPy 版本一起使用的最小示例配置,从一个空ubuntu:bionic图像开始。version: 2jobs:&nbsp; build:&nbsp; &nbsp; docker:&nbsp; &nbsp; &nbsp; - image: ubuntu:bionic&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.5.5&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.14.2&nbsp; &nbsp; steps:&nbsp; &nbsp; &nbsp; - checkout&nbsp; &nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: Setup Miniconda&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; apt update&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; apt install -y wget&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cd $HOME&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wget "https://repo.anaconda.com/miniconda/Miniconda3-4.7.10-Linux-x86_64.sh" -O miniconda.sh&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf '%s' "8a324adcc9eaf1c09e22a992bb6234d91a94146840ee6b11c114ecadafc68121&nbsp; miniconda.sh" | sha256sum -c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bash miniconda.sh -b -p $HOME/miniconda&nbsp; &nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: Setup environment and run tests&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH="$HOME/miniconda/bin:$PATH"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda update -y conda&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda create -n myenv python=$PYTHON_VERSION -c conda-forge&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source activate myenv&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda install -y numpy=$NUMPY_VERSION&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python --version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python -c "import numpy; print(numpy.__version__)"我认为Miniconda3-4.7.10-Linux-x86_64.sh从 Internet 下载 Miniconda 安装脚本后验证校验和是一种很好的做法。您可以更改环境变量PYTHON_VERSION并NUMPY_VERSION获取其他版本。目前我们只是要验证我们想要的 Python 和 NumPy 版本是否与python --version和一起使用,而不是“真正的”测试python -c "import numpy; print(numpy.__version__)"。对于上面的示例,您应该在日志的末尾找到:Python 3.5.51.14.2根据您选择的版本,您可能会收到错误消息:如果您得到PackagesNotFoundError,则需要确保所选频道具有您要查找的软件包版本。(上例中选择了Like conda-forge。)如果您得到UnsatisfiableError,则您选择了不兼容的软件包版本。以下是多个版本的示例配置:version: 2workflows:&nbsp; version: 2&nbsp; test:&nbsp; &nbsp; jobs:&nbsp; &nbsp; &nbsp; - python_3.5&nbsp; &nbsp; &nbsp; - python_3.6&nbsp; &nbsp; &nbsp; - python_3.7template: &template&nbsp; docker:&nbsp; &nbsp; - image: ubuntu:bionic&nbsp; steps:&nbsp; &nbsp; - checkout&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Setup Miniconda&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; apt update&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; apt install -y wget&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cd $HOME&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wget "https://repo.anaconda.com/miniconda/Miniconda3-4.7.10-Linux-x86_64.sh" -O miniconda.sh&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf '%s' "8a324adcc9eaf1c09e22a992bb6234d91a94146840ee6b11c114ecadafc68121&nbsp; miniconda.sh" | sha256sum -c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bash miniconda.sh -b -p $HOME/miniconda&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Setup environment and run tests&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH="$HOME/miniconda/bin:$PATH"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda update -y conda&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda create -n myenv python=$PYTHON_VERSION&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source activate myenv&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda install -y pip numpy=$NUMPY_VERSION&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python --version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pip --version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python -c "import numpy; print(numpy.__version__)"jobs:&nbsp; python_3.5:&nbsp; &nbsp; <<: *template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.5&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.14.2&nbsp; python_3.6:&nbsp; &nbsp; <<: *template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.6&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.15.2&nbsp; python_3.7:&nbsp; &nbsp; <<: *template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.7&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.16.5如果我将此最小示例应用于您的案例,则配置将类似于以下内容:version: 2.0workflows:&nbsp; version: 2&nbsp; test:&nbsp; &nbsp; jobs:&nbsp; &nbsp; &nbsp; - py3.6-np1.15&nbsp; &nbsp; &nbsp; - py3.5-np1.15&nbsp; &nbsp; &nbsp; - py3.6-np1.14&nbsp; &nbsp; &nbsp; - py3.5-np1.14&nbsp; &nbsp; &nbsp; - py3.7-np1.15&nbsp; &nbsp; &nbsp; - py3.6-np1.16&nbsp; &nbsp; &nbsp; - py3.7-np1.16test-template: &test-template&nbsp; docker:&nbsp; &nbsp; - image: ubuntu:bionic&nbsp; steps:&nbsp; &nbsp; - checkout&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Install System Dependencies&nbsp; &nbsp; &nbsp; &nbsp; command: apt-get update && apt-get install -y libmpich12 libmpich-dev build-essential&nbsp; &nbsp; # Download and cache dependencies&nbsp; &nbsp; - restore_cache:&nbsp; &nbsp; &nbsp; &nbsp; keys:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - v1-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: install anaconda&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; apt update&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; apt install -y wget&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cd $HOME&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chmod +x ~/miniconda.sh && bash ~/miniconda.sh -b -p $HOME/miniconda&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH=$HOME/miniconda/bin:$PATH&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Install numpy, cython, mdtraj&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH="$HOME/miniconda/bin:$PATH"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda update&nbsp; --yes conda&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $PYTHON_VERSION&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda create -n myenv python=$PYTHON_VERSION -c conda-forge&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source activate myenv&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda install --yes pip&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda install --yes -c conda-forge numpy=$NUMPY_VERSION cython=$CYTHON_VERSION&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conda install --yes -c conda-forge nose mdtraj&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python --version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python -c "import numpy; print(numpy.__version__)"&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Install and build package&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH=$HOME/miniconda/bin:$PATH&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source activate myenv&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pip install --progress-bar off .[dev]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python setup.py build_ext --inplace&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; python setup.py install&nbsp; &nbsp; - save_cache:&nbsp; &nbsp; &nbsp; &nbsp; paths:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - ~/miniconda&nbsp; &nbsp; &nbsp; &nbsp; key: v1-dependencies-{{ checksum "setup.py" }}&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Run non-MPI tests&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH=$HOME/miniconda/bin:$PATH&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source activate myenv&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nosetests -a '!mpi' package&nbsp; &nbsp; - run:&nbsp; &nbsp; &nbsp; &nbsp; name: Run MPI tests&nbsp; &nbsp; &nbsp; &nbsp; command: |&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; export PATH=$HOME/miniconda/bin:$PATH&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; source activate myenv&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OMP_NUM_THREADS=1 mpiexec -n 2 nosetests -a mpi package&nbsp; &nbsp; - store_artifacts:&nbsp; &nbsp; &nbsp; &nbsp; path: test-reports&nbsp; &nbsp; &nbsp; &nbsp; destination: test-reportsjobs:&nbsp; py3.6-np1.15:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.14.2&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.26.1&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.6&nbsp; py3.5-np1.15:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.14.2&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.26.1&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.5&nbsp; py3.6-np1.14:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.14.2&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.26.1&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.6&nbsp; py3.5-np1.14:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.14.2&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.26.1&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.5&nbsp; py3.7-np1.15:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.15.2&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.26.1&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.7.1&nbsp; py3.6-np1.16:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.16.5&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.26.1&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.6&nbsp; py3.7-np1.16:&nbsp; &nbsp; <<: *test-template&nbsp; &nbsp; environment:&nbsp; &nbsp; &nbsp; NUMPY_VERSION: 1.16.5&nbsp; &nbsp; &nbsp; CYTHON_VERSION: 0.29.2&nbsp; &nbsp; &nbsp; PYTHON_VERSION: 3.7.1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python