You are not logged in.

#1 2020-06-02 11:16:01

SpeedCola
Member
Registered: 2020-05-02
Posts: 25

Python venv activation doesn't work?

Hey,

I have a file `install.sh` with the following contents:

#!/usr/bin/env bash

# Create Python virtual environment
python -m venv --prompt PROJECT-NAME .env

# Activate the environment
source .env/bin/activate

# Install requirements
pip install -r requirements.txt

It creates the environment, but it doesn't activate it.

If I do the 'source .env/bin/activate' manually, it works.

Have to mention that I use zsh as the main shell.

Offline

#2 2020-06-02 11:44:42

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 653

Re: Python venv activation doesn't work?

That script actually does run correctly. I.e. it sources the newly created environment and runs pip in it. When you run that script you are creating a child shell (i.e. the top shebang line) which sources that environment, runs pip, and then promptly terminates. So instead of typing `./install,sh`, type `source tmp.sh` to run those commands in your current shell and give you the result you are probably expecting.

Offline

#3 2020-06-02 15:19:01

SpeedCola
Member
Registered: 2020-05-02
Posts: 25

Re: Python venv activation doesn't work?

Thanks that worked.

Offline

Board footer

Powered by FluxBB