I have installed virtualenvwrapper-win and when I try this command
workon <envname>
In CMD it works, but not in Windows PowerShell.
In Windows PowerShell I have to do Scripts\activate.ps1
and then I get the envname before the prompt.
Can you please let me know how can I make workon command working in PowerShell?
To activate the virtual environment, go to the directory where you installed it and run the following command by replacing "env" with your environment name. To install any package make sure the virtual environment is active. Use the following command to install the package.
Setting up virtualenv This can be done by activating the activate script in the Scripts folder. The following command creates an activate. bat batch file after activation. This creates an activate.
To install virtualenv, just use pip install virtualenv . To create a virtual environment directory with it, type virtualenv /path/to/directory .
Now after creating virtual environment, you need to activate it. Remember to activate the relevant virtual environment every time you work on the project. This can be done using the following command: Note: source is a shell command designed for users running on Linux (or any Posix, but whatever, not Windows).
workon
is a batch script. If you run it from PowerShell it's launched in a new CMD child process, doing its thing there, then exit and return to the PowerShell prompt. Since child processes can't modify their parent you lose all modifications made by workon.bat
when you return to PowerShell.
You basically have two options:
Rewrite workon.bat
(and the other batch scripts it calls) in PowerShell.
Run workon.bat
in without exiting from the CMD child process:
& cmd /k workon <envname>
If you just want a shortcut workon
that you can call directly from PowerShell you can wrap that commandline in a function and put the function definition into your PowerShell profile:
function workon($environment) {
& cmd /k workon.bat $environment
}
Use the scriptname with extension here to avoid infinite recursion.
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