> For the complete documentation index, see [llms.txt](https://kdongs.gitbook.io/kdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdongs.gitbook.io/kdocs/python-3/install-and-create.md).

# Install & Create

## Install

Install python with [`pyenv`](https://github.com/pyenv/pyenv).

```bash
sudo apt update; sudo apt install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl git \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
```

```bash
curl -fsSL https://pyenv.run | bash
```

```bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc
```

```bash
source ~/.bashrc
```

#### List available versions to install

```bash
pyenv install -l
```

#### Install a version

```bash
pyenv install <version>
```

#### Set global version

```bash
pyenv global <version>
```

#### Check global version

```bash
pyenv global
```

## Creating a Project

### Virtual Environement

You can create projects with a `package.json` alike way, with [`venv`](https://docs.python.org/3/library/venv.html).&#x20;

When using Virtual Environments, dependencies installed via `pip` will be installed at a project scope, instead of globally.

#### Create the environment

```bash
python -m venv <.somename-env>

# Usually
python -m venv .venv
```

**Active the environment**

```bash
# In Windows
.\<.somename-env>\Scripts\activate
.\<.somename-env>\bin\activate

# In Linux
source <.somename-env>/bin/activate
```

**Deactivate**

```bash
deactivate
```

**Create `requirements.txt`**

This file will act like a `package.json`, saving the dependencies.

```bash
pip freeze > requirements.txt
```

**To reinstall from a `requirements.txt`**

Will have to recreate the environment first.

```bash
pip install -r requirements.txt
```
