Article on creating a virtual environment for a project in Windows via Visual Studio Code
Please note this article is only for those who want create a virtual environment for a project in Windows via Visual Studio Code, not via cmd and etc.
Step 1: Creating a virtual environment
py -3 -m venv .myproject
– This command creates a virtual environment named “myproject”.
Step 2: Activating the virtual environment
.myprojectscriptsactivate
– This command activates the virtual environment in Windows, allowing you to use isolated packages and dependencies for your project.
Step 3: Deactivating the virtual environment
deactivate
– Enter this command when you want to stop using the virtual environment and return to the system environment.
Optional: Setting execution policy
You should only enter the command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
if you encounter issues when executing scripts or activating the virtual environment in PowerShell. For example, if you receive an error message related to script execution policy when trying to activate the virtual environment, changing the PowerShell execution policy may help resolve the issue. You should enter this command after the first step, and then all subsequent commands.
This guide can also help those who are trying to enter these commands through the Visual Studio Code terminal and encounter an error message like :
The module '.myproject' could not be loaded. For more information, run 'Import-Module .myproject'.
At line:1 char:1
+ .myprojectscriptsactivate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.myprojectscriptsactivate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule"
or
source : The term 'source' 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
+ source env/bin/activate
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
These commands will allow you to create, activate, and deactivate a virtual environment for your project in Windows using the Visual Studio Code terminal.
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ