# Using virtualenv and pip

> Create isolated Python environments with virtualenv and install or remove packages with pip.

Source: https://helpcenter.ruachost.com/developers/programming-languages/using-virtualenv-and-pip/

**Using virtualenv and pip**\
Learn how to create isolated Python environments and manage Python packages using `virtualenv` and `pip`.

These programs allow you to ensure that your Python applications have the exact environment and dependencies they need, without interfering with system-wide Python installations.

## Important

- On shared hosting accounts, use the **Python Selector** to manage Python environments.
- Managed VPS and Dedicated servers activated in May 2023 or later should also use the Python Selector.
- For managed VPS/Dedicated servers activated before May 2023, follow the steps below.

## Creating and activating a Python environment with virtualenv

1. **Log in via SSH**.
2. Ensure you are in your home directory:

```
cd ~
```

3. Create a new environment (replace `project` with your desired name):

```
virtualenv project
```

- By default, `virtualenv` uses the system Python version (commonly 2.7).
- To use a specific Python version, such as Python 3:

```
virtualenv -p python3 project
```

4. Activate the environment:

```
source project/bin/activate
```

- When active, your prompt shows `(project)` at the beginning.

5. To exit the environment, type:

```
deactivate
```

## Using pip to manage Python packages

`pip` is installed automatically when you create a virtual environment with `virtualenv`.

1. **Activate the environment** (if not already active):

```
source ~/project/bin/activate
```

2. **Search for a package**:

```
pip search pkgname
```

- Example: Search for MySQL-related packages:

```
pip search mysql
```

3. **Install a package**:

```
pip install pkgname
```

4. **Uninstall a package**:

```
pip uninstall pkgname
```

## More information

- [virtualenv documentation](http://www.virtualenv.org/)
- [pip documentation](http://www.pip-installer.org/)
