2

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.

kissu
  • 40,416
  • 14
  • 65
  • 133
  • 2
    Please (also) post your code, data, error messages as _text_, [not (just) as _images_](https://meta.stackoverflow.com/a/285557/45375). – mklement0 Jul 12 '21 at 20:52

3 Answers3

4

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.

lit
  • 14,456
  • 10
  • 65
  • 119
1

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.

vicaris-
  • 141
  • 3
0

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

  • 1
    Good point, but it isn't just _sometimes_: In order to execute a script located in the _current directory_, PowerShell _always_ requires you to explicitly prefix the script name with `.\ ` (or `./`). – mklement0 Jul 12 '21 at 20:50