Today I was following a tutorial about Flask for python. While doing this I ran into a problem. I created a folder for my project. Then installed virtual environment module.
pip install virtual env
ran successfully, module virualenv is now installed
virtualenv env
this command also ran successfully. a virtual environment with name env is created.
so we have created a virtual environment. now to activate we need to run a batch file form inside the env folder.
env\Scripts\activate.bat
This will not run in power-shell because its a batch file.
so I tried the next option.
env\Scripts\activate.ps1
this gave an error.
.\env\Scripts\activate.ps1 : File D:\Userfiles\Desktop\Py Flask\env\Scripts\activate.ps1 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.
so how to activate our virtual environment?
lets remove the restriction.
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
the above command will enable running scripts for current user. we can disable this with the following command after we finish.
Set-ExecutionPolicy -Scope CurrentUser Restricted
running scripts is now enabled. lets try again.,with
.\env\Scripts\activate.ps1
It works! yay..