Search code examples
pythonpython-3.xwindowspython-venv

python virtualenv not activated on windows 11


Im using python 10 and windows-11 i try to activate venv with the following command

.\onlineShop\Scripts\activate.bat

I create venv using following command

python -m venv onlineShop

My pip list

Package      Version
------------ -------
distlib      0.3.4
filelock     3.6.0
pip          22.0.4
platformdirs 2.5.2
pyaes        1.6.1
Pyrogram     2.0.17
PySocks      1.7.1
setuptools   58.1.0
six          1.16.0
virtualenv   20.14.1

also when Im using .\onlineShop\Scripts\activate gives me this Error

"cannot be loaded because the execution of scripts is disabled on this system".

Problem : venv is not activated


Solution

  • According to Microsoft Tech Support, it might be a problem with Execution Policy Settings. To fix it, you should try executing the Set-ExecutionPolicy Unrestricted -Scope Process

    OR IF this problem is not gone Then please read this answer

    To activate

    .\<Virtual-Name>\Scripts\activate
    

    or

    .\<Virtual-Name>\Scripts\activate.bat
    

    FOR deactivating venv

    .\<Virtual-Name>\Scripts\deactivate.bat
    

    or

    .\<Virtual-Name>\Scripts\deactivate
    

    or

    deactivate 
    

    If you got this error while activating the virtual Environment:

    cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.

    This means your Execution Policy is Restricted SO. To get rid of this error you can run this command.

    In Command Prompt:

    powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
    

    In Powershell:

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
    

    Replace <Virtual-Name> with your virtual environment name