Python Virtual Environment working in Command Prompt, but not in Powershell

Viewed 721

Picture of the virtual environment working in Command Prompt, and not working in Powershell with the error I've been trying to get this virtual environment to work with powershell, but I keep getting this error. The virtual environment works in Command Prompt, but not in Powershell, so I've been wondering what I can do to fix that.

3 Answers

There are three (3) "activate" scripts in the venv scripts directory.

PS C:\venv\py39\Scripts> (Get-ChildItem -Filter 'act*').Name
activate
activate.bat
Activate.ps1

These are used in the following shells.

activate        # bash
activate.bat    # cmd.exe
Activate.ps1    # powershell.exe or pwsh.exe

Use the following for PowerShell.

.\Activate.ps1

The Activate.ps1 script includes a deactivate function. Therefore, no deactivate.ps1 script is needed.

Primary issue is that PowerShell - as you can see on your screenshot - doesn't load commands from the current location by default. Just as it suggests you, try to use .\activate instead of activate.

But that also might not help and lead to other issue connected to the Execution Policies. The command throws some security exceptions after trying to activate the virtual environment. And as it is completly different thing and in order to not duplicate answers, I will redirect you to this thread which should help you with that.

Sometimes I have gotten that error, instead of activate, try .\activate.ps1

Related