Solve the problem that PowerShell cannot enter the Python virtual environment under Windows

PowerShell can be said to be an upgraded version of CMD, it will be completed, copy and paste is also very convenient, the specific differences are not explained here.
Recently, a python virtual environment was set up under Windows for development and testing. At the beginning, CMD can successfully enter the virtual environment for testing. Once switched to PowerShell, the virtual environment cannot be entered.

Cannot enter the virtual environment

Insert picture description here

solution:

You need to run PowerShell as an administrator and then execute the command:
Set-ExecutionPolicy RemoteSigned
Then select Y to successfully set
At first, I forgot to open it as an administrator. As a result, the statement could not be executed:

Insert picture description here

Open as an administrator:

Insert picture description here

Whether it is started by an administrator is as follows:

Insert picture description here

Enter the virtual environment again after setting, success!

Insert picture description here

note

Sometimes you will encounter this situation. When you start the virtual environment, enter a+tab in the Scripts directory to automatically complete'.\activate.bat'.
If so, press Enter and find that there is no response and you did not successfully enter the virtual environment. , The problem is that you do not need to add a suffix to start the virtual environment:

PS E:\project\facebook\venv\Scripts> .\activate.bat # 执行该语句未响应
PS E:\project\facebook\venv\Scripts> .\activate
(venv) PS E:\project\facebook\venv\Scripts> 

Guess you like

Origin blog.csdn.net/Lin_Hv/article/details/105842899