Cannot make Virtual Envoirment

Question:

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

.venvscriptsactivate : File C:Usersnatha.venvscriptsActivate.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
+ .venvscriptsactivate
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

This is the command i am using on windows 11

py -3 -m venv .venv
.venvscriptsactivate

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

Asked By: The github guy

||

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:UserskyrlonDesktop> py -m venv env1
PS C:UserskyrlonDesktop> .env1Scriptsactivate
(env1) PS C:UserskyrlonDesktop> deactivate env1
PS C:Usersklongwood3Desktop> py -m venv env1

OR

PS C:UserskyrlonDesktop> python -m venv env1
PS C:UserskyrlonDesktop> .env1Scriptsactivate
(env1) PS C:UserskyrlonDesktop> deactivate env1
PS C:Usersklongwood3Desktop> 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:Userskyrlon>py -m venv py_venv
C:Userskyrlon>.py_venvScriptsactivate.bat
(py_venv) C:Userskyrlon>

OR

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

C:Userskyrlon>python -m venv py_venv
C:Userskyrlon>.py_venvScriptsactivate.bat
(py_venv) C:Userskyrlon>
Answered By: kyrlon
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.