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.

No `VIRTUAL_ENV` variable available?

See original GitHub issue

Description: In an activated Python virtual environment (venv), the environment variable VIRTUAL_ENV contains the path to the base of the venv. That variable doesn’t exists, and it doesn’t seem possible to activate the environment in the action either? I could pass in that variable but then I’d have to make an assumption about where this Action installs Python on the runner.

Action version: v3, latest

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version: I tried with 3.9 and 3.10 and it failed for both.

Repro steps:
Failed activate:

No VIRTUAL_ENV variable:

Expected behavior: Either being able to activate the environment (which is tricky from an Action considering the differences between Windows (Scripts/ folder) and Linux/Mac (bin/ folder). Ideally, the VIRTUAL_ENV would be set?

Actual behavior: The variable isn’t available.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vsafonkincommented, Jul 21, 2022

@jenstroeger, it’s correct. You can use GITHUB_ENV to pass values between steps.

- name: venv activate Linux
  run: |
    mkdir test-venv
    cd test-venv
    python -m venv .
    source ./bin/activate
    echo "VIRTUAL_ENV: $VIRTUAL_ENV"
    echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV

- name: test
  run: |
    echo "VIRTUAL_ENV: $VIRTUAL_ENV"
1reaction
vsafonkincommented, Mar 29, 2022

@jenstroeger, the setting up and activation of venv are not in scope of setup-python action because using of venv is not mandatory for all python developers, someone can use the other tools and packages. The main goal of setup-python action is installation of required python version on the runner.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setting an environment variable in virtualenv - Stack Overflow
Using only virtualenv (without virtualenvwrapper), setting environment variables is easy through the activate script you're sourcing in order to activate ...
Read more >
Set environment variables in a Python venv (Windows)
This is a brief overview of the possibilities for setting environment variables in a virtual environment (venv).
Read more >
Python: Three Different Ways to Store Environment Variables
Store Environment Variables in Virtual Environment​​ You can also choose to store your environment variables within a virtual environment; the environment  ...
Read more >
venv — Creation of virtual environments — Python 3.11.1 ...
When a virtual environment has been activated, the VIRTUAL_ENV environment variable is set to the path of the environment. Since explicitly activating a...
Read more >
How to use Python Virtualenv and Environment variables on ...
How to use Python Virtualenv and Environment variables on windows. TutorialSupport the channelPaypal.
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