Cannot make Virtual Envoirment

Viewed 43

I have been following all the steps VSC's tutorial ia giving me but i keep running into this error

py : The term 'py' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling 
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ py -3 -m venv .venv
+ ~~
    + CategoryInfo          : ObjectNotFound: (py:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

.venv\scripts\activate : File C:\Users\natha\.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:2 char:1
+ .venv\scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

This is the command i am using on windows 11

py -3 -m venv .venv
.venv\scripts\activate

I do not know what's going on because I've been following the tutorial on vs code

1 Answers

Take a look at this post. With windows, running py or python in a terminal (command prompt, PowerShell, git bash) should work in making a virtual environment. From your post, you are attempting to run this virtual environment in PowerShell. You would need to allow execution of PowerShell scripts (by example mentioned here). In a nutshell, open PowerShell as an Administrator, and run the command set-executionpolicy remotesigned or run set-executionpolicy unrestricted (mentioned here. Now you should be able to make a new virtual environment as so:

PS C:\Users\kyrlon\Desktop> py -m venv env1
PS C:\Users\kyrlon\Desktop> .\env1\Scripts\activate
(env1) PS C:\Users\kyrlon\Desktop> deactivate env1
PS C:\Users\klongwood3\Desktop> py -m venv env1

OR

PS C:\Users\kyrlon\Desktop> python -m venv env1
PS C:\Users\kyrlon\Desktop> .\env1\Scripts\activate
(env1) PS C:\Users\kyrlon\Desktop> deactivate env1
PS C:\Users\klongwood3\Desktop> python -m venv env1

An alternative is to use command prompt as such:

Microsoft Windows [Version 10.0.19044.1889]
(c) Microsoft Corporation. All rights reserved.

C:\Users\kyrlon>py -m venv py_venv
C:\Users\kyrlon>.\py_venv\Scripts\activate.bat
(py_venv) C:\Users\kyrlon>

OR

Microsoft Windows [Version 10.0.19044.1889]
(c) Microsoft Corporation. All rights reserved.

C:\Users\kyrlon>python -m venv py_venv
C:\Users\kyrlon>.\py_venv\Scripts\activate.bat
(py_venv) C:\Users\kyrlon>
Related