powershell: activate python virtualenv using shortcut

Issue

All my virtualenvs are put into a venv folder which is inside the project folder.

If I want to activate the virtualenv when inside the project folder I need to enter:

.\venv\Scripts\Activate.ps1 

Having to do this many times I really find this cumbersome. And I am looking for something quicker. From inside my project folder I’d like to type act or something which then automatically activates the .ps1 script.

But not being familiar with powershell and all the options available I wonder if someone could give me some clues where to start ? (batch script? cmd script? powershell script? shortcut (.lnk) file?)

Thanks !

Solution

What you want to use is called an alias

In Windows you will use it this way :

New-Alias <nom-alias> <commande>

To make it persistant (be able to use it again after closing and reopening the powershell) you need to put the alias in a configuration file.

Answered By – Tim

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published