{{tag>Python PUB}}
= Note Python pip
Voir aussi :
* [[https://linuxfr.org/news/python-partie-6-pip-et-pipx|pipx]]
* poetry
**Do not run pip install as root (or with sudo)**
Installation dans ~/.local/bin/
easy_install --user pip
Liste des "packages" installés dans la sessions de l'utilisateur :
pip freeze --local
Ou
python -m ensurepip
Voir aussi **pipreqs**
Installer un package depuis un dépôt git
pip install --user git+https://github.com/benoit-intrw/livestreamer
Mise à jour des "packages" locaux
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)
pip install --user livestreamer
Tous mettre à jour localement
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
env1/bin/pip freeze > requirements.txt
env2/bin/pip install -r requirements.txt
Voir aussi **pipreqs**
Exemple de fichier requirements.txt
''requirements.txt''
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''
export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages/:$HOME/test/lib/python3.5/site-packages/
Utiliser /usr/local
''~/.config/pip/pip.conf''
[global]
target = /usr/local/lib/python2.7/site-packages
Ou
PIP_TARGET=/usr/local/lib/python2.7/site-packages
''~/.bashrc''
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
== Exemple de PIP en interne
''pip.conf''
[global]
timeout = 300
index-url = https://pypi.acme.fr/pypi/+simple/
cert = /etc/ssl/certs/ca-certificates.crt
''pip.conf''
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
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
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:
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
python3 -m pip install --user pipx
python3 -m pipx ensurepath