Files
mkdocs/docs/macos/python/pip.md
2023-11-14 20:35:51 +01:00

570 lines
13 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# pip
## Installation:
### Installer pip (python 2):
[:fa-link: https://apple.stackexchange.com/questions/209572/how-to-use-pip-after-the-os-x-el-capitan-upgrade](https://apple.stackexchange.com/questions/209572/how-to-use-pip-after-the-os-x-el-capitan-upgrade)
##### Documentation pip:
[:fa-link: https://pip.pypa.io/en/stable/](https://pip.pypa.io/en/stable/)
### Installer pip3 (python 3):
#### Installer pip:
```bash
$ sudo easy_install pip
```
Pour [Python 3](python3.md), **pip** est installé d'origine.
#### Version courrante de pip:
```bash
$ pip3 --version
pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
```
#### Mettre à jour pip:
```bash
$ sudo pip install --upgrade pip
```
```bash
$ pip3 install --user --upgrade pip
```
!!! attention
Sur macOS, à cause de SIP (System Integrity Protection), l'installation se fait avec le mot-clé —user
#### Cache:
Linux and Unix
```bash
~/.cache/pip # and it respects the XDG_CACHE_HOME directory.
```
OS X
```bash
~/Library/Caches/pip
```
Windows
```bash
%LocalAppData%\pip\Cache
```
pip peut installer en ignorant le cache:
```bash
$ pip3 --no-cache-dir install mkdocs
```
## Environnement virtuel:
Création de l'environnement virtuel pour l'application MkDocs:
```bash
# Création de l'environnement virtuel
$ python3 -m venv mkdocs_env
# Mise-à-jour
$ mkdocs_env/bin/pip3 install -U pip setuptools
# Installation de mkdocs
$ mkdocs_env/bin/pip3 install mkdocs
# Installation du thème
$ mkdocs_env/bin/pip3 install mkdocs-material pymdown-extensions pygments
# Installation des plugins
$ mkdocs_env/bin/pip3 install mkdocs-pdf-export-plugin mkdocs-minify-plugin mkdocs-pdf-export-plugin
# Installation du plugin depuis les sources
# $ mkdocs_env/bin/pip3 install mkdocs-pdf-export-plugin-0.5.5.tar.gz
# Mise-à-jour
$ mkdocs_env/bin/pip3 install -U mkdocs
# Mise-à-jour de l'environnement virtuel
$ python3 -m venv --upgrade mkdocs_env
up_venv() {
/Users/bruno/Documents/venv/$1/bin/python3 -m venv --upgrade $1
}
$ up_venv mkdocs
# Mise-à-jour de l'application dans un venv
up_venv_mod() {
pip_venv="/Users/bruno/Documents/venv/$1/bin/pip3"
$pip_venv list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 $pip_venv install -U
}
$ up_venv_mod mkdocs
```
Initialisation et démarrage de MkDocs:
```bash
~/Documents/docs master*
# Création d'un nouveau projet
$ ~/Documents/venv/mkdocs/bin/mkdocs new ~/Documents/docs
INFO - Writing config file: /Users/bruno/Documents/docs/mkdocs.yml
INFO - Writing initial docs: /Users/bruno/Documents/docs/docs/index.md
# Démarrage de mkdocs
$ ~/Documents/venv/mkdocs/bin/mkdocs serve
INFO - Building documentation...
INFO - Cleaning site directory
```
L'activation n'est pas obligatoire, elle simplifie juste les chemins.
```bash
~/Documents/mydocs master*
$ source ~/Documents/mkdocs_env/bin/activate
~/Documents/mydocs master*
mkdocs_env mkdocs serve
~/Documents/mydocs master*
mkdocs_env deactivate
```
Mise-à-jour des modules:
```bash
up_venv_mod() {
/Users/bruno/Documents/venv/$1/bin/pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
}
$ up_venv mkdocs_env
```
## Modules:
#### Installer des modules (depuis [PyPi](https://pypi.org)):
##### Installer un module:
```bash
$ pip3 install django
$ python3 -m pip install dango
```
Les modules sont ici:
`/usr/local/lib/python3.7/site-packages`
`/usr/local/lib/python3.8/site-packages`
##### Installer un module pour l'utilisateur courant (mkdocs):
```bash
$ pip3 install --user mkdocs
```
Les modules sont ici:
`/Users/bruno/Library/Python/3.7/lib/python/site-packages`
#### Installer des modules (depuis une archive):
```bash
$ pip3 install mkdocs-pdf-export-plugin-0.5.5.tar.gz
```
#### Installer des modules (depuis les sources):
```bash
~/Downloads/
$ cd mkdocs-pdf-export-plugin-0.5.5
~/Downloads/mkdocs-pdf-export-plugin-0.5.5
$ pip3 install .
```
#### Installer des modules (depuis un [VCS](https://pip.pypa.io/en/latest/reference/pip_install/#vcs-support)):
```bash
$ pip3 install -e git+https://github.com/zhaoterryy/mkdocs-pdf-export-plugin.git#egg=mkdocs-pdf-export-plugin
# avec un commit
$ pip3 install -e git+https://github.com/zhaoterryy/mkdocs-pdf-export-plugin.git@7c6c82c96490a84b4bd617e21977259f60dd5007#egg=mkdocs-pdf-export-plugin
# avec un tag
$ pip3 install -e git+https://github.com/zhaoterryy/mkdocs-pdf-export-plugin.git@v0.5.3#egg=mkdocs-pdf-export-plugin
$ pip3 install -e "git+ssh://git.example.com/MyProject#egg=MyProject"
```
#### Requirements files:
[*requirements.txt*](https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format) est une liste de modules à installer.
```bash
$ pip3 install -r requirements.txt
$ pip3 freeze > requirements.txt
$ pip3 install -r requirements.txt
```
#### Installer une version précise d'un module:
```bash
$ pip3 show tornado
Name: tornado
Version: 5.0
.../...
$ pip3 install tornado==4.5.3
Collecting tornado==4.5.3
Installing collected packages: tornado
Found existing installation: tornado 5.0
Uninstalling tornado-5.0:
Successfully uninstalled tornado-5.0
Successfully installed tornado-4.5.3
$ pip3 install 'tornado>=4.1.0,<4.5.3'
# Installe une version comprise entre 4.1.0 et 4.5.3
$ pip3 install 'tornado~=4.5.2'
# Installe une version “==4.5.*” qui est aussi “>=4.5.2”.
```
#### Spécifier la version:
```bash
# Opérateurs: ==, >, >=, <, <=, !=, ~=, ===
docopt == 0.6.1 # Correspondance de version. La version doit être 0.6.1
# exclu pre-releases, post releases, developmental releases et 0.6.1.x maintenance releases.
docopt == 0.6.* # Correspondance de version. La version doit commencer par 0.6. Idem ~= 0.6.0
keyring >= 4.1.1 # Version minimale 4.1.1
coverage != 3.5 # Version Exclue. Tout sauf la version 3.5
Mopidy-Dirble ~= 1.1 # Compatible release. Idem >= 1.1, == 1.* (>= 1.1 AND == 1.*)
# version 1.1 ou plus, mais exclu 2.0 ou plus
tornado ~= 4.5.3 # Compatible release. Idem >= 4.5.3, == 4.5.*
# version 4.5.3 ou plus, mais exclu 4.6.0 ou plus
tornado === 4.5.3 # Arbitrary equality (Égalité arbitraire)
# On peut spécifier 2 conditions:
package >= 1.0, <=2.0 # Version comprise entre 1.0 et 2.0
# Si aucune version n'est spécifiée, la dernière version est installée:
beautifulsoup4
tornado
```
[PEP 440](https://www.python.org/dev/peps/pep-0440/#version-specifiers)
#### Désinstaller un module:
```bash
$ pip3 uninstall <module>
```
#### Informations sur un module:
```bash
$ pip3 show <module>
$ pip3 show mkdocs
Name: mkdocs
Version: 0.17.2
Summary: Project documentation with Markdown.
Home-page: http://www.mkdocs.org
Author: Tom Christie
Author-email: tom@tomchristie.com
License: BSD
Location: /Users/bruno/Library/Python/2.7/lib/python/site-packages
Requires: tornado, PyYAML, click, Markdown, Jinja2, livereload
```
#### Installer une liste de modules requis:
```bash
$ pip3 install -r requirements.txt
```
#### Liste des modules installés:
```bash
# --format=columns (par defaut)
$ pip3 list
Package Version
-------------------------------------- ---------
altgraph 0.10.2
backports-abc 0.5
bdist-mpkg 0.5.0
```
```bash
$ pip3 freeze
appnope==0.1.0
attrs==18.2.0
autopep8==1.4.3
backcall==0.1.0
bleach==3.1.0
Click==7.0
decorator==4.3.2
defusedxml==0.5.0
Django==2.1.7
# Exporter la liste
$ pip3 freeze > export_liste_pip.txt
# puis l'importer sur une autre machine
$ pip3 install -r export_liste_pip.txt
# Ou créer un bundle
$ pip3 bundle <nom_du_bundle>.pybundle -r export_liste_pip.txt
# et importer les lib
$ pip3 install <nom_du_bundle>.pybundle
```
#### Liste des modules mis-à-jour:
```bash
$ pip3 list --outdated
Package Version Latest Type
-------------------------------------- -------- ------ -----
altgraph 0.10.2 0.15 wheel
macholib 1.5.1 1.9 wheel
matplotlib 1.3.1 2.1.1 wheel
```
```bash
$ pip3 list --outdated --format=freeze
packaging==16.8
Sphinx==1.7.0
```
```bash
$ pip3 list --outdated --format=columns
Package Version Latest Type
------
packaging 16.8 17.1 wheel
Sphinx 1.7.0 1.7.1 wheel
```
```bash
$ pip3 list --outdated --format=legacy
packaging (16.8) - Latest: 17.1 [wheel]
Sphinx (1.7.0) - Latest: 1.7.1 [wheel]
```
```bash
$ pip3 list --outdated --format=json
[{"name": "packaging", "version": "16.8", "latest_version": "17.1", "latest_filetype": "wheel"}, {"name": "Sphinx", "version": "1.7.0", "latest_version": "1.7.1", "latest_filetype": "wheel"}]
```
#### Mettre à jour un module:
```bash
$ pip3 install --upgrade <module>
$ pip3 install -U django
```
```bash
$ pip3 install --user --upgrade <module>
$ pip3 install --user -U mkdocs-material
```
#### Mettre à jour tous les modules:
```bash
$ pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
```
#### Chercher un module:
```bash
$ pip3 search <module>
$ pip3 search mkdocs-pdf-export-plugin
mkdocs-pdf-export-plugin (0.5.5) - An MkDocs plugin to export content pages as PDF files
INSTALLED: 0.5.5 (latest)
mkdocs-mk2pdf-plugin (0.1.5) - An MkDocs plugin to export content pages as PDF files
INSTALLED: 0.1.5 (latest)
mkdocs-autolinks-plugin (0.2.0) - An MkDocs plugin
mkdocs-with-pdf (0.1.0) - Generate a single PDF file from MkDocs repository
mkdocs-toc-sidebar-plugin (0.1.0) - An MkDocs plugin
mkdocs-tooltipster-links-plugin (0.1.0) - An MkDocs plugin
```
#### Connaitre toutes les versions disponibles d'un module:
*Depuis pypi.org avec curl:*
```bash
# $ curl -L -s "https://pypi.org/pypi/<$PACKAGE>/json" | jq -r '.releases | keys | .[]' | sort -V
$ curl -L -s "https://pypi.org/pypi/geomet/json" | jq -r '.releases | keys | .[]' | sort -V
0.1.0
0.1.1
0.1.2
0.2.0.post2
0.2.1
0.2.1.post1
0.3.0
```
*pip >= 21.2*
```bash
$ pip index versions geomet
WARNING: pip index is currently an experimental command. It may be removed/changed in a future release without prior warning.
geomet (0.3.0)
Available versions: 0.3.0, 0.2.1.post1, 0.2.0.post2, 0.1.2, 0.1.1, 0.1.0
INSTALLED: 0.3.0
LATEST: 0.3.0
```
*Précédentes versions de pip:*
```bash
# en ne précisant pas la version
$ pip install geomet==
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
ERROR: Ignored the following versions that require a different python version: 0.2.1 Requires-Python >2.6, !=3.3.*, <3.8
ERROR: Could not find a version that satisfies the requirement geomet== (from versions: 0.1.0, 0.1.1, 0.1.2, 0.2.0.post2, 0.2.1.post1, 0.3.0)
ERROR: No matching distribution found for geomet==
```
```bash
$ pip install geomet== --use-deprecated=legacy-resolver
```
```bash
# en spécifiant une version qui n'existe pas:
$ pip install geomet==9999
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
ERROR: Ignored the following versions that require a different python version: 0.2.1 Requires-Python >2.6, !=3.3.*, <3.8
ERROR: Could not find a version that satisfies the requirement geomet==9999 (from versions: 0.1.0, 0.1.1, 0.1.2, 0.2.0.post2, 0.2.1.post1, 0.3.0)
ERROR: No matching distribution found for geomet==9999
```
## Dépendances:
#### Montrer les dépendances d'un module:
```bash
$ pip3 show mkdocs | grep Requires
Requires: click, Markdown, PyYAML, Jinja2, tornado, lunr, livereload
```
#### Vérifier les paquets installés:
```bash
$ pip3 check
mkdocs 1.1.2 has requirement lunr[languages]==0.5.8, but you have lunr 0.5.9.
```
#### pipdeptree:
Savoir quel module requiert tel module (dépendances inverses):
```bash
$ pipdeptree -r -p mkdocs
mkdocs==1.1
- mkdocs-material==4.6.3 [requires: mkdocs>=1.0]
- mkdocs-minify-plugin==0.2.3 [requires: mkdocs>=1.0.4]
- mkdocs-mk2pdf-plugin==0.1.5 [requires: mkdocs>=0.17]
- mkdocs-pdf-export-plugin==0.5.5 [requires: mkdocs>=0.17]
- mkdocs-windmill==1.0.4 [requires: mkdocs]
- mkpdfs-mkdocs==1.0.1 [requires: mkdocs>=0.17]
```
Montrer les dépendances:
```bash
$ pipdeptree -p mkdocs
mkdocs==1.1
- click [required: >=3.3, installed: 7.1]
- Jinja2 [required: >=2.10.1, installed: 2.11.1]
- MarkupSafe [required: >=0.23, installed: 1.1.1]
- livereload [required: >=2.5.1, installed: 2.6.1]
- six [required: Any, installed: 1.14.0]
- tornado [required: Any, installed: 6.0.4]
- lunr [required: ==0.5.6, installed: 0.5.6]
- future [required: >=0.16.0, installed: 0.18.2]
- six [required: >=1.11.0, installed: 1.14.0]
- Markdown [required: >=3.2.1, installed: 3.2.1]
- setuptools [required: >=36, installed: 46.0.0]
- PyYAML [required: >=3.10, installed: 5.3]
- tornado [required: >=5.0, installed: 6.0.4]
```
## Configuration:
```bash
$ pip3 config edit
```