

# Python



#### Python 3 est installé par défaut:

```bash title="Python3"
$ which python
/bin/python

$ python -V
Python 3.8.15


$ which python3
/bin/python3

$ /bin/python3 -V
Python 3.8.15


# Les modules sont installés là: 
# /usr/lib/python3.8/site-packages

$ find / -iname "site-packages" -type d -print 2>/dev/null
```



#### Python 2 est aussi installé:

```bash title="Python2"
$ python2 -V
Python 2.7.18

$ which python2
/usr/local/bin/python2

# Les modules sont installés là: 
# /usr/local/lib/python2.7/site-packages
```



!!!warning "pip n'est pas installé par défaut"

```bash title="Installer pip"
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

python3 get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Using cached pip-21.1.3-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  WARNING: The scripts pip, pip3 and pip3.8 are installed in '/var/services/homes/bruno/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.1.3

# Ajouter /volume1/homes/bruno/.local/bin au $PATH

# Utiliser sudo pour une install globale
```

```bash title="Chemins en installation locale"
$ which pip3

$ pip3 --version
pip 23.2.1 from /var/packages/python311/target/lib/python3.11/site-packages/pip (python 3.11)
```



#### Mieux vaut créer un environnement virtuel:

```bash title="Création de l'environnement virtuel"
bruno@DS916:~/venv $ python3 -m venv mkdocs
```

```bash title="Activation"
bruno@DS916:~/venv $ source mkdocs/bin/activate
```

```bash title="Mise-à-jour de pip et setuptools"
(mkdocs) bruno@DS916:~/venv $ pip3 install -U pip setuptools
```

```bash title="Installation de mkdocs"
(mkdocs) bruno@DS916:~/venv $ pip3 install -U mkdocs
```

```bash title="Dé-activation"
(mkdocs) bruno@DS916:~/venv $ deactivate
```

```bash title="Version de mkdocs"
/var/services/homes/bruno/venv/mkdocs/bin/mkdocs --version
mkdocs, version 1.2.1 from /volume1/homes/bruno/venv/mkdocs/lib/python3.8/site-packages/mkdocs (Python 3.8)
```



#### Paquets Python 3.9 et Python 3.11 SynoCommunity

```bash
$ which python3.9
/usr/local/bin/python3.9

$ which python3.11
/usr/local/bin/python3.11

$ python3 -V
Python 3.11.5

# /volume1/@appstore/Python3.9/usr/lib/python3.9/site-packages
#		<vide>

# /volume1/@appstore/python311/lib/python3.11/site-packages
#		pip 23.2.1

# /volume1/homes/bruno/.local/lib/python3.11/site-packages
#		pipx 1.6.0

```



#### pipx

```bash
$ which pipx
/var/services/homes/bruno/.local/bin/pipx

# Virtual Environment location is /volume1/homes/bruno/.local/share/pipx/venvs.
# Symlinks to apps are placed in /volume1/homes/bruno/.local/bin.
# Symlinks to manual pages are placed in /volume1/homes/bruno/.local/share/man.

$ pipx -v
pipx >(setup:1083): pipx version is 1.6.0
```

Upgrade pipx:

```
python3 -m pip install --user -U pipx
```

Commandes:

```
    install             Install a package
    upgrade             Upgrade a package
    upgrade-all         Upgrade all packages. Runs `pip install -U <pkgname>` for each package.
    uninstall           Uninstall a package
    uninstall-all       Uninstall all packages
    reinstall           Reinstall a package
    reinstall-all       Reinstall all packages
    list                List installed packages

```



```bash
$ pipx list
venvs are in /volume1/homes/bruno/.local/share/pipx/venvs
apps are exposed on your $PATH at /volume1/homes/bruno/.local/bin
manual pages are exposed at /volume1/homes/bruno/.local/share/man
   package showcert 0.2.3, installed using Python 3.11.5
    - gencert
    - showcert
```

