question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple python versions in one environment

See original GitHub issue

Some tools are designed to have access to multiple python interpreters, and then create their own virtualenvs. Tox is a common example (although there are other ways to use tox in Actions). Less common, but my use case, is maturin https://github.com/PyO3/maturin , which is used to build rust crates with python bindings. It’s a lot quicker to do them all at once rather than in different jobs, as most of the compiled code is shared.

It would be helpful if setup-python allowed users to pass an array of python versions and installed all of them (which one takes python is up for debate, but python3.7, python3.8 etc should be fine).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:42
  • Comments:5

github_iconTop GitHub Comments

1reaction
btcross26commented, May 24, 2021

I was able to use the Miniconda action as shown below to accomplish the OP’s mention for tox with multiple Pythons in one invocation, where I am testing a Python library for 3.7, 3.8, and 3.9. Note the bash -l {0} is required for the Miniconda action to work properly across steps. Below, the testenv environment is automatically active at each step. Essentially, I just create the extra Python environments using conda and append the paths for the Python binaries in those environments to the PATH when running tox in the testing environment.

name: build_tests
on: [push]
jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    name: Run tox build tests
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash -l {0}
    steps:
      - name: Setup repo
        uses: actions/checkout@v2
      - uses: conda-incubator/setup-miniconda@v2
        with:
          miniconda-version: latest
          python-version: 3.8
          activate-environment: testenv
          channels: conda-forge
      - name: Setup conda python environments
        run: |
          conda config --set always_yes yes --set changeps1 no
          conda install -q -c conda-forge tox
          conda create -q -n py37 python=3.7
          conda create -q -n py39 python=3.9
      - name: Run pytest
        env:
          TOXENV: py37,py38,py39
        run: |
          export PY37_PATH=$CONDA/envs/py37/bin
          export PY39_PATH=$CONDA/envs/py39/bin
          export PATH=$PATH:$PY37_PATH:$PY39_PATH
          tox
      - name: Run code checks
        if: ${{ matrix.os == 'ubuntu-latest' }}
        env:
          TOXENV: typing,pypi-description,manifest,precom
        run: tox
1reaction
AraHaancommented, Oct 20, 2020

I would go for installing x86 and x64 python’s at same time as well, expecially if it means generating python c extension modules depending on the platform.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to manage multiple Python versions and virtual ...
If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and...
Read more >
Multiple Python versions on the same machine?
Old Answer: Install Python from source · 1) Install Required Packages for source compilation · 2) Download and extract desired Python version ·...
Read more >
Managing Multiple Python Versions With pyenv
pyenv is a wonderful tool for managing multiple Python versions. Even if you already have Python installed on your system, it is worth...
Read more >
How to Install and Manage Multiple Python Versions on Linux
How to Install and Manage Multiple Python Versions on Linux · Check the Default Version: · Check the Executable File: · Open the...
Read more >
How to Install and Manage Multiple Python Versions on ...
This article uses a simple technique to install and manage multiple python versions without PyEnv. It installs every major version of python, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found