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
?
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.
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.
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 .
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.
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