Outils pour utilisateurs

Outils du site


tech:python_pip

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:python_pip [2025/09/24 12:08] Jean-Baptistetech:python_pip [2026/07/16 15:11] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Python PUB}}
 +
 +# Note Python pip
 +
 +Voir aussi :
 +* [|pipx](https://linuxfr.org/news/python-partie-6-pip-et-pipx)
 +* poetry
 +
 +Voir uv : remplace pip, pipx, poetry, pyenv, 
 +* https://blog.stephane-robert.info/docs/developper/programmation/python/uv/
 +* [uv](https://docs.astral.sh/uv/)
 +
 +
 +**Do not run pip install as root (or with sudo)**
 +
 +
 +Installation dans ~/.local/bin/
 +~~~bash
 +easy_install --user pip
 +~~~
 +
 +Liste des "packages" installés dans la sessions de l'utilisateur :
 +~~~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://github.com/benoit-intrw/livestreamer
 +~~~
 +
 +Mise à jour des "packages" locaux
 +~~~bash
 +pip install --local -U livestreamer
 +~~~
 +
 +Installation d'un "package" dans la session de l'utilisateur (pas besoin de droit root) (pas besoin de prendre le risque d’abîmer sa distro)
 +
 +~~~bash
 +pip install --user livestreamer
 +~~~
 +
 +Tous mettre à jour localement
 +~~~bash
 +pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U
 +~~~
 +Source http://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip
 +
 +Fichier requirements.txt
 +~~~bash
 +env1/bin/pip freeze > requirements.txt
 +env2/bin/pip install -r requirements.txt
 +~~~
 +Voir aussi **pipreqs**
 +
 +Exemple de fichier requirements.txt
 +
 +`requirements.txt`
 +~~~python
 +numpy>=1.15.0
 +opencv-python>=3.4.2.17
 +pandas>=0.23.3 --no-binary pandas
 +Pillow>=5.2.0
 +tensorflow==1.8.0
 +tensorflow-gpu==1.8.0
 +~~~
 +
 +Variable Python - utiliser les dist-packages depuis un environnement virtuel
 +
 +`~/.bashrc`
 +~~~bash
 +export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages/:$HOME/test/lib/python3.5/site-packages/
 +~~~
 +
 +Utiliser /usr/local
 +
 +`~/.config/pip/pip.conf`
 +~~~ini
 +[global]
 +target = /usr/local/lib/python2.7/site-packages
 +~~~
 +
 +Ou 
 +~~~bash
 +PIP_TARGET=/usr/local/lib/python2.7/site-packages
 +~~~
 +
 +`~/.bashrc`
 +~~~bash
 +export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
 +~~~
 +
 +
 +## Exemple de PIP en interne
 +
 +`pip.conf`
 +~~~ini
 +[global]
 +timeout = 300
 +index-url = https://pypi.acme.fr/pypi/+simple/
 +cert = /etc/ssl/certs/ca-certificates.crt
 +~~~
 +
 +`pip.conf`
 +~~~bash
 +mkdir -p ~/.pip/ && \
 +echo "[global]" >> ~/.pip/pip.conf && \
 +URLPIP="https://artifactory.packages.install-os.acme.local/api/pypi/ext_pypi/simple" && \
 +echo "index = $URLPIP " >> ~/.pip/pip.conf && \
 +echo "index-url = $URLPIP " >> ~/.pip/pip.conf && \
 +echo "cert = /etc/ssl/certs/ca-certificates.crt " >> ~/.pip/pip.conf 
 +~~~
 +
 +
 +
 +## Autres
 +
 +~~~bash
 +ssh -R3128:192.168.56.1:3128 user@192.168.205.11
 +
 +export http_proxy=http://127.0.0.1:3128
 +export https_proxy=http://127.0.0.1:3128
 +
 +python3 -m venv test
 +cd test
 +source bin/activate
 +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, starting from the most recent version, until it finds a version that is compatible with the given constraints.
 +
 +
 +## pipx
 +
 +~~~bash
 +python3 -m pip install --user pipx
 +python3 -m pipx ensurepath
 +~~~
 +
 +
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki