> For the complete documentation index, see [llms.txt](https://fastapi-docs.duonghuuphuc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fastapi-docs.duonghuuphuc.com/appendix-e.md).

# Appendix E

## `virtualenvwrapper` Cheatsheet

***

### 1. Installation

For **Apple macOS**, the installation is executed via this command:

```
pip install virtualenvwrapper
```

Then, open the `zshrc` via Terminal and insert the following configuration at the bottom:

```
# Virtualenvwrapper configuration
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Development   # Optional: default directory for projects
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source $(which virtualenvwrapper.sh)
```

For **Microsoft Windows**, you can use the `virtualenvwrapper-win` which can be run under Microsoft Windows Command Prompt. The installation is also executed via `pip` command as follows:

```
pip install virtualenvwrapper-win
```

You can read more information of the `virtualenvwrapper-win` at <https://pypi.org/project/virtualenvwrapper-win/>

***

### 2. Basic commands

| Action                                   | Apple macOS                | Microsoft Windows          |
| ---------------------------------------- | -------------------------- | -------------------------- |
| **Create an environment**                | `mkvirtualenv <name>`      | `mkvirtualenv <name>`      |
| **Activate / Switch environment**        | `workon <name>`            | `workon <name>`            |
| **List all environments**                | `workon` or `lsvirtualenv` | `workon` or `lsvirtualenv` |
| **Deactivate active environment**        | `deactivate`               | `deactivate`               |
| **Delete an environment**                | `rmvirtualenv <name>`      | `rmvirtualenv <name>`      |
| **Create project folder + env together** | `mkproject <name>`         | `mkproject <name>`         |
| **Install single packages**              | `pip install <package>`    | `pip install <package>`    |

***

### 3. Example flow of commands

```
# 0. Create an enviroment (run only once)
$ mkvirtualenv mysoa

# 1. Activate the target microservice environment
$ workon mysoa

# 2. Install single packages (run only once)
$ pip install fastapi uvicorn

# 3. Install from a dependency file
pip install -r requirements.txt

# 4. Deactive the current enviroment
$ deactivate
```

***

### 4. Reference

* <https://virtualenvwrapper.readthedocs.io/>
* <https://pypi.org/project/virtualenvwrapper-win/>
* <https://www.python.org/>
* <https://pypi.org/>
