> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using virtualenv and pip

> Discover how to install and manage virtualenv and pip in Python with this step-by-step guide and related resources.

This article describes how to use the *virtualenv* and *pip* programs. The *virtualenv* program enables you to create custom Python environments, while the *pip* program enables you to install Python packages. By using these programs, you can ensure your Python applications have the exact environment setup that they need to function correctly.

<Warning>
  **Important**

  * On shared, reseller, and Turbo hosting accounts, you should use the Python Selector to install and manage Python environments. For information about how to use the Python Selector, please see [this article](/docs/using-the-python-selector).

  * For managed VPS and Dedicated server accounts activated **in May 2023 or after**, you should use the Python Selector to install and manage Python environments. For information about how to use the Python Selector, please see [this article](/docs/using-the-python-selector). (To determine if the Python Selector is available on your server, please see [this article](/docs/determining-if-your-hosting-account-uses-cloudlinux).)

  * For managed VPS and Dedicated server accounts activated **before** May 2023, follow the procedures below to set up your Python environments.
</Warning>

## Using virtualenv to create and activate an environment

The *virtualenv* program allows you to create your own custom Python environments. A custom environment has its own installation directories, Python executables, packages, and modules. This means you can install any specific versions that an application may require. Because the environment is isolated, you do not have to worry about other programs installing incompatible versions or otherwise breaking the application's configuration.

To create a custom Python environment using *virtualenv*, follow these steps:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. To make sure you are in your home directory, type the following command at the command line:

   ```bash theme={null}
   cd ~
   ```

3. To create the environment, type the following command. You can replace ***project*** with any name you want:

   ```bash theme={null}
   virtualenv project
   ```

   *Virtualenv* sets up the Python environment and installs the *pip* program.

   > 📘 Note
   >
   > By default, *virtualenv* installs the system-wide Python version, which is currently version 2.7. To install a specific Python version in the environment, use the **-p** option. For example, to create an environment that uses Python 3, type the following command:
   >
   > ```bash theme={null}
   > virtualenv -p python3 project
   > ```

4. To use the new environment, you must activate it first. To do this, type the following command:

   ```bash theme={null}
   source project/bin/activate
   ```

   > 👍 Tip
   >
   > When the environment is active, the command prompt begins with **(project)** , where *project* is the environment name.

5. When you are done working in the environment, type the following command:

   ```bash theme={null}
   deactivate
   ```

The command prompt returns to normal.

## Using pip to install Python packages

When you set up a custom Python environment with *virtualenv*, the *pip* program is installed as well. You can use the *pip* installer to install a large selection of Python packages into custom environments.

To use the *pip* program, follow these steps:

1. If you have not already activated the environment, do so now. Type the following command, replacing ***project*** with the environment name:

   ```bash theme={null}
   source ~/project/bin/activate
   ```

2. After the environment is activated, you can use the *pip* program to install and manage Python packages:

   * To search for a specific package or set of packages, type the following command. Replace ***pkgname*** with the name of the package that you want to search for:

     ```bash theme={null}
     pip search pkgname
     ```

     > 👍 Tip
     >
     > For example, to search for all MySQL-related packages, type **pip search mysql** .

   * To install a Python package, type the following command. Replace ***pkgname*** with the name of the package that you want to install:

     ```bash theme={null}
     pip install pkgname
     ```

   * To uninstall a Python package, type the following command. Replace ***pkgname*** with the name of the package that you want to uninstall:

     ```bash theme={null}
     pip uninstall pkgname
     ```

## More information

* For more information about virtualenv, please visit [http://www.virtualenv.org](http://www.virtualenv.org).

* For more information about pip, please visit [http://www.pip-installer.org](http://www.pip-installer.org).

## Related articles

* [Python script basics](/docs/python-script-basics)
