tech:python_pip
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:python_pip [2025/09/24 12:08] – Jean-Baptiste | tech:python_pip [2026/07/16 15:11] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Note Python pip | ||
| + | |||
| + | Voir aussi : | ||
| + | * [|pipx](https:// | ||
| + | * poetry | ||
| + | |||
| + | Voir uv : remplace pip, pipx, poetry, pyenv, | ||
| + | * https:// | ||
| + | * [uv](https:// | ||
| + | |||
| + | |||
| + | **Do not run pip install as root (or with sudo)** | ||
| + | |||
| + | |||
| + | Installation dans ~/ | ||
| + | ~~~bash | ||
| + | easy_install --user pip | ||
| + | ~~~ | ||
| + | |||
| + | Liste des " | ||
| + | ~~~bash | ||
| + | pip freeze --local | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Ou | ||
| + | ~~~bash | ||
| + | python -m ensurepip | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Voir aussi **pipreqs** | ||
| + | |||
| + | Installer un package depuis un dépôt git | ||
| + | ~~~bash | ||
| + | pip install --user git+https:// | ||
| + | ~~~ | ||
| + | |||
| + | Mise à jour des " | ||
| + | ~~~bash | ||
| + | pip install --local -U livestreamer | ||
| + | ~~~ | ||
| + | |||
| + | Installation d'un " | ||
| + | |||
| + | ~~~bash | ||
| + | pip install --user livestreamer | ||
| + | ~~~ | ||
| + | |||
| + | Tous mettre à jour localement | ||
| + | ~~~bash | ||
| + | pip freeze --local | grep -v ' | ||
| + | ~~~ | ||
| + | Source http:// | ||
| + | |||
| + | Fichier requirements.txt | ||
| + | ~~~bash | ||
| + | env1/ | ||
| + | env2/ | ||
| + | ~~~ | ||
| + | Voir aussi **pipreqs** | ||
| + | |||
| + | Exemple de fichier requirements.txt | ||
| + | |||
| + | `requirements.txt` | ||
| + | ~~~python | ||
| + | numpy> | ||
| + | opencv-python> | ||
| + | pandas> | ||
| + | Pillow> | ||
| + | tensorflow==1.8.0 | ||
| + | tensorflow-gpu==1.8.0 | ||
| + | ~~~ | ||
| + | |||
| + | Variable Python - utiliser les dist-packages depuis un environnement virtuel | ||
| + | |||
| + | `~/.bashrc` | ||
| + | ~~~bash | ||
| + | export PYTHONPATH=$PYTHONPATH:/ | ||
| + | ~~~ | ||
| + | |||
| + | Utiliser /usr/local | ||
| + | |||
| + | `~/ | ||
| + | ~~~ini | ||
| + | [global] | ||
| + | target = / | ||
| + | ~~~ | ||
| + | |||
| + | Ou | ||
| + | ~~~bash | ||
| + | PIP_TARGET=/ | ||
| + | ~~~ | ||
| + | |||
| + | `~/.bashrc` | ||
| + | ~~~bash | ||
| + | export PYTHONPATH=$PYTHONPATH:/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Exemple de PIP en interne | ||
| + | |||
| + | `pip.conf` | ||
| + | ~~~ini | ||
| + | [global] | ||
| + | timeout = 300 | ||
| + | index-url = https:// | ||
| + | cert = / | ||
| + | ~~~ | ||
| + | |||
| + | `pip.conf` | ||
| + | ~~~bash | ||
| + | mkdir -p ~/.pip/ && \ | ||
| + | echo " | ||
| + | URLPIP=" | ||
| + | echo "index = $URLPIP " >> ~/ | ||
| + | echo " | ||
| + | echo "cert = / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~bash | ||
| + | ssh -R3128: | ||
| + | |||
| + | export http_proxy=http:// | ||
| + | export https_proxy=http:// | ||
| + | |||
| + | python3 -m venv test | ||
| + | cd test | ||
| + | source bin/ | ||
| + | pip install -U pip | ||
| + | # pip install --use-feature=2020-resolver plop | ||
| + | pip install --no-binary pandas pandas | ||
| + | #deactivate | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | export PIP_BREAK_SYSTEM_PACKAGES=1 | ||
| + | ~~~ | ||
| + | |||
| + | Voir [[mise_a_jour_repos_git]] | ||
| + | |||
| + | |||
| + | ### constraints | ||
| + | |||
| + | You can achieve this with a constraints file. Just put all your constraints into that file: | ||
| + | |||
| + | `constraints.txt` | ||
| + | ~~~ | ||
| + | google-api-core==1.16.0 | ||
| + | ~~~ | ||
| + | |||
| + | Then you can install via: | ||
| + | ~~~bash | ||
| + | python -m pip install -c constraints.txt google-cloud-secret-manager | ||
| + | ~~~ | ||
| + | This will try every version of google-cloud-secret-manager, | ||
| + | |||
| + | |||
| + | ## pipx | ||
| + | |||
| + | ~~~bash | ||
| + | python3 -m pip install --user pipx | ||
| + | python3 -m pipx ensurepath | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
