Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Self Hosted Windows Runner - Execute steps in a python virtual environment

skaul April 14, 2025

Following is how my pipeline yaml file looks like.

definitions:
step:
- step: &GenerateExe
name: Generate Exe
runs-on:
- self.hosted
- windows
script:
- git config --global core.autocrlf input
- git config --global --add safe.directory '*'
- git lfs pull
- mkvirtualenv temp_py310
- workon temp_py310
- python -m pip list
- python -m pip install -r requirements.txt
- python -m pip list
- python generate_versions_rc.py
- pyinstaller --log-level=DEBUG MYEXE.spec
- rmvirtualenv temp_py310
artifacts:
- dist/**
after-script:
- rmvirtualenv temp_py310
pipelines:
default:
- step: *GenerateExe

It looks like each individual step is a different "powershell" command or script. I want to run the python commands from inside the virtual environment called "temp_py310". Are there better methods available in the bitbucket to do the same? 

Something similar to WithENV(Pipeline: Basic Steps) in jenkins. 

1 answer

1 accepted

1 vote
Answer accepted
ashu patel
Contributor
April 14, 2025

To ensure your Python steps run within the virtual environment (temp_py310), you should activate it explicitly before running your Python commands. In a Windows runner, if you’re using virtualenv, the activation is typically done using:

script:
- python -m venv temp_py310
- call temp_py310\Scripts\activate
- python -m pip install -r requirements.txt
- python generate_versions_rc.py
- pyinstaller --log-level=DEBUG MYEXE.spec

If you want something like withEnv from Jenkins, grouping everything under a single step is the closest option in Bitbucket Pipelines.

skaul April 14, 2025

This works thanks. Just a minor change.

.\temp_py310\Scripts\activate.ps1

As this is getting executed in a powershell on windows. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events