Learn Python – Creating, Installing and Using Virtual Environment in Python


virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

On Windows:


Creating virtualenv:

virtualenv allows you to manage separate package installations for different projects. It essentially allows you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtualenv while developing Python applications.

On macOS and Linux:

On Windows:


Activating a virtualenv:

Before you can start installing or using packages in your virtualenv you’ll need to activate it. Activating a virtualenv will put the virtualenv-specific python and pip executables into your shell’s PATH.

On macOS and Linux:

On Windows:

**Remember env is the virtual environment you have created**

Leaving the virtualenv:

If you want to switch projects or otherwise leave your virtualenv, simply run:

Installing packages:

Now that you’re in your virtualenv you can install packages. Let’s install the excellent Requests library from the Python Package Index (PyPI):

Leave A Reply

Your email address will not be published.