DEV Community

Shantanu Nighot
Shantanu Nighot

Posted on • Originally published at magbanum.tech on

1 1

A virtual environment in Powershell.

a virtual environment in powershell
The virtual environment is used to create an isolated environment for the different projects. This helps developers to keep the dependencies required by projects separate. So let's learn basic commands to create and activate the virtual env and install packages on it.

Prerequisites,

  • Python
  • PIP

Install virtualenv package using the following command,

python -m pip install --user virtualenv
Enter fullscreen mode Exit fullscreen mode

Now go to the folder where you want to create a virtual environment and run the following command to create a virtual environment with the name "env". This will create the folder named "env" in a directory.

python -m venv env
Enter fullscreen mode Exit fullscreen mode

You can name it whatever you what just make it logical and relative to your project.

To activate the virtual environment, go to the directory where you installed it and run the following command by replacing "env" with your environment name.

env\Scripts\activate
Enter fullscreen mode Exit fullscreen mode

To install any package make sure the virtual environment is active. Use the following command to install the package.

pip install package-name
Enter fullscreen mode Exit fullscreen mode

To install multiple packages use a comma , to separate package names. For example,

pip install requests, Django, BeautifulSoup
Enter fullscreen mode Exit fullscreen mode

To install packages using requirements.txt file, use the following command

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

To get package names installed on a virtual environment into a requirements.txt file use the following command.

pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

To deactivate the env use,

deactivate
Enter fullscreen mode Exit fullscreen mode

I am a total beginner and might have missed command that I never used before. So, please comment below few commands that are helpful for developers. Thanks for reading and do follow for more such articles.

Never stop learning!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay