Files
mkdocs/docs/macos/python/python3.md
2020-03-07 08:26:20 +01:00

200 lines
3.3 KiB
Markdown
Raw 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.
# Python 3
Python 3 peut s'installer avec Homebrew:
```bash
$ brew install python3
```
Les extensions Python 3 s'installent dans `/usr/local/lib/python3.7/site-packages/`
Pour lancer un script Python 3:
```bash
$ python3 script.py
```
Pour que python pointe sur Python 3 (homebrew), rajouter ceci à .bash_profile:
```bash
export PATH=/usr/local/opt/python/libexec/bin:$PATH
```
Pip est installé d'origine avec Python 3. On le lance avec la commande **pip3**:
```bash
$ pip list --outdated --format=columns
$ pip install mkdocs
```
Installation utilisateur:
```bash
$ python3 -m site --user-base
/Users/bruno/Library/Python/3.7
```
[Pipenv](https://docs.pipenv.org)
### idle:
**idle** est l'éditeur par défaut de Python
Pour le lancer depuis le shell:
```bash
$ idle
```
[Python et tcl/tk versions](https://discussions.apple.com/thread/8066794)
Python 3 utilise la bibliothèque Tcl/Tk fournie par macOS (8.5.9).
Pour utiliser une version plus récente (8.6.8) de la bibliothèque :
```bash
$ brew install tcl-tk
$ brew reinstall python3 --with-tcl-tk
```
#### jupyter:
[jupyter](https://jupyter.org/) est une web application qui permet de créer et partager des documents contenant du live-code...
Installer:
```bash
$ pip install jupyter
```
Démarrer:
```bash
$ jupyter notebook
```
### Modules:
#### Global
```bash
$ pip install <module>
```
Les modules s'installent dans `/usr/local/lib/python3.7/site-packages` :
Liste des modules:
```bash
$ pip freeze
appnope==0.1.0
asgiref==3.2.3
backcall==0.1.0
```
#### Local
```bash
$ pip install --user <module>
```
Les modules s'installent dans `/Users/bruno/Library/Python/3.7/lib/python/site-packages/` :
Liste des modules:
```bash
$ pip freeze --user
Click==7.0
tornado==6.0.3
```
#### Mkdocs
Il faut installer Mkdocs avec pip dans --user
```bash
$ pip install --user mkdocs
```
Mkdocs s'installe dans `/Users/bruno/Library/Python/3.7/bin` :
```bash
~/Library/Python/3.7/bin$ ./mkdocs --version
mkdocs, version 1.0.4 from /Users/bruno/Library/Python/3.7/lib/python/site-packages/mkdocs (Python 3.7)
```
On peut ajouter le chemin au $PATH, en ajoutant la ligne suivante au .zshrc ou .bash_profile:
```bash
export PATH=/Users/bruno/Library/Python/3.7/bin:$PATH
```
On installe de la même manière le thème [Material](https://squidfunk.github.io/mkdocs-material/getting-started/):
```bash
$ pip install --user mkdocs-material
```
#### Django
[Installer Django](Django.md)
#### Rechercher un module
[PyPI - the Python Package Index](https://pypi.python.org/pypi)
#### Problème à l'installation
Erreur lors de linstall de python3 avec Homebrew:
```bash
bruno@HackiMac:/usr/local/bin$ brew install python3
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.0.high_sierra.bottle.3.tar.gz
Already downloaded: /Users/bruno/Library/Caches/Homebrew/downloads/d76c2354ae237f190a868bb74f28d606b88cce724222bafa114e91cd8a1462d5--python-3.7.0.high_sierra.bottle.3.tar.gz
==> Pouring python-3.7.0.high_sierra.bottle.3.tar.gz
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
```
Solution:
```bash
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
```