Reputation: 65
When I run venv\Scripts\activate
in cmd, I am able to use venv but in VS Code I can not use venv and I get this error:
PS F:\Python\Python-Inoventaa\Python Flask\FlaskProject\FlaskBlogProject> venv\Scripts\activate
venv\Scripts\activate :
File F:\Python\Python-Inoventaa\Python Flask\FlaskProject\FlaskBlogProject\venv\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.
At line:1 char:1
+ venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Upvotes: 3
Views: 15940
Reputation: 71
As mentioned in the previous answer, it is due to execution policy of PowerShell terminal in VSCode.
To bypass the execution policy while using VSCode, you may add a modified PowerShell profile and set it as default profile in the JSON settings:
"terminal.integrated.profiles.windows": {
"PowerShell venv": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-ExecutionPolicy", "Bypass"] }},
"terminal.integrated.defaultProfile.windows": "PowerShell venv",
or you may also choose to modify the default PowerShell, mentioned by @John:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-ExecutionPolicy", "Bypass"] }},
"terminal.integrated.defaultProfile.windows": "PowerShell",
Upvotes: 2
Reputation: 1
Changing to cmd instead of powershell will definitely work in vs code
Upvotes: 0
Reputation: 648
You can use this script on VS Code's terminal:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
for more detail you can visit official VS Code website about Python programming at https://code.visualstudio.com/docs/python/python-tutorial
Upvotes: 3
Reputation: 19
Try this: On the terminal of vs-code at the right side selected cmd instead of power shell.
Upvotes: 0
Reputation: 21
You can solve it by adding this configuration to your settings.json file suggested from this issue
By going to your settings.json (on windows):
%APPDATA%\Code\User\settings.json
or
C:\Users\<your user>\AppData\Roaming\Code\User\settings.json
and adding this line in the configuration (use comma at the end if there are more config lines):
{
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
}
and it should be solved once you open another Terminal.
Upvotes: 2
Reputation: 396
Try this: On the terminal of vs-code at the right side selected cmd instead of power shell.
see the image: https://i.sstatic.net/QxRPS.png
Upvotes: 13