I need to setup a virtual environment, and install the requirements for my Flask app.
However, an error occurs here:
sudo apt install python3-venv
sudo python3.8 -m venv venv
This is the .yml
file for my GitHub Actions.
name: TEST
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup system group
run: |
if [ ! $( getent group uni ) ]; then sudo addgroup --system uni; fi
- name: Setup system user
run: |
if [[ $(getent passwd uni) = "" ]]; then sudo adduser --no-create-home --force-badname --disabled-login --disabled-password --system uni; fi
- name: Add user user to group
run: |
sudo usermod -g uni uni
- name: Setup base directory
working-directory: /
run: |
if [ ! -d ./uni/test/app ]; then sudo mkdir -p ./uni/test/app; fi
sudo chown uni:uni -R /uni/test
sudo chmod 775 -R /uni/test
- name: Setup log directory
working-directory: /var/log
run: |
if [ ! -d ./uni/test ]; then sudo mkdir -p ./uni/test; fi
sudo chown uni:uni -R ./uni/test
sudo chmod 755 -R ./uni/test
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Setup Python virtual environment
working-directory: /uni/test/app
run: |
sudo apt install python3-venv
sudo python3.8 -m venv venv
- name: Install dependencies
working-directory: /uni/test/app/venv
run: |
source ./bin/activate
pip install --upgrade pip
pip install wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
deactivate
What am I doing wrong here?
And is there a way I can install python3-venv inside the block below?
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
GitHub provides several actions that can be used, such as setup-python , which we will use to install Python. You can read more about this Action and different capabilities, such as Matrix testing, versioning, and caching at the official documentation here.
I just tested a simple workflow here (same as below) to use the virtual env.
It doesn't seem you need the sudo apt install python3-env
command when using the actions/checkout
and the setup-python
actions to create the virtual env using the python3.8 -m venv env
command.
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Run Python commands
run: |
pip install --upgrade pip
python3.8 -m venv env
source env/bin/activate
echo "VIRTUAL ENV:" $VIRTUAL_ENV
Returned me VIRTUAL ENV: /home/runner/work/poc-github-actions/poc-github-actions/env
on the workflow run logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With