Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a postactivate script using Python 3 venv?

I'm using venv (used pyvenv to create the environment) and would like to set up environment variables here, but postactivate looks like a virtualenv thing. Can this be done with venv?

like image 907
StringsOnFire Avatar asked Aug 20 '16 16:08

StringsOnFire


People also ask

How do I set environment variables in VENV?

ps1. If you want to set environment variables each time the venv is started, you can assign them inside the activation script. If you're running a PowerShell terminal, you should edit Activate. ps1 in <YOUR_ENV>/Scripts and add an extra line to set an environment variable as follows.

How do I run VENV from terminal in python?

Search in your applications for the Terminal and open it. Enter into your Desktop folder with the command cd desktop . Type python3 -m venv env to create a virtual environment named env . When the environment is created, the prompt will reappear.

How do I run a virtual environment in Python?

To use the virtual environment you created to run Python scripts, simply invoke Python from the command line in the context where you activated it. For instance, to run a script, just run python myscript.py .


1 Answers

venv has the activate script which you can modify to add your environment variables.

I would add the variables at the bottom, making a nice comment block to clearly separate the core functionality and my custom variables.

like image 151
masnun Avatar answered Sep 28 '22 05:09

masnun