Vous n'êtes pas identifié(e).
L'icône rouge permet de télécharger chaque page du wiki visitée au format
PDF et la grise au format ODT →
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | Prochaine révision Les deux révisions suivantes | ||
utilisateurs:hypathie:tutos:developpement-pyhon-utiliser-django [08/12/2015 14:16] Hypathie [Configurations et installation de Django avec SQLite3] |
utilisateurs:hypathie:tutos:developpement-pyhon-utiliser-django [08/12/2015 14:23] Hypathie [Avant de commencer] |
||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
- | =====Avant de commencer ==== | + | ===== Installations ===== |
- | Sur Jessie python et python 3 sont tous deux installés. | + | **Installer les outils et bibliothèques pour développer en python ou python3** |
- | ==== Installer les outils et bibliothèques pour développer en python ou python 3 ==== | + | <note tip> |
+ | Sur Jessie, python et python 3 sont tous deux installés. | ||
+ | </note> | ||
* Fichiers d'en-tête de Python | * Fichiers d'en-tête de Python | ||
Ligne 63: | Ligne 65: | ||
<code root>apt-get install tree</code> | <code root>apt-get install tree</code> | ||
- | |||
- | ====Préparer son système pour travailler avec python2 et python3==== | ||
- | |||
- | ===Utiliser update-alternatives pour choisir l'une ou l'autre des versions:=== | ||
- | |||
- | * Charger les différentes versions de Python : | ||
- | |||
- | <code root>update-alternatives --list python</code> | ||
- | <code retour>update-alternatives: error: no alternatives for python</code> | ||
- | |||
- | * Pour voir où sont les exécutables des deux versions disponibles de python : | ||
- | |||
- | <code user> ls /usr/bin/python*</code> | ||
- | <code retour> | ||
- | /usr/bin/python /usr/bin/python3 /usr/bin/python3-config | ||
- | /usr/bin/python2 /usr/bin/python3.4 /usr/bin/python3m | ||
- | /usr/bin/python2.7 /usr/bin/python3.4-config /usr/bin/python3m-config | ||
- | /usr/bin/python2.7-config /usr/bin/python3.4m /usr/bin/python-config | ||
- | /usr/bin/python2-config /usr/bin/python3.4m-config | ||
- | </code> | ||
- | |||
- | * Pour ajouter à la liste de update-alternatives les deux versions de python disponibles : | ||
- | (ici par exemple; "/usr/bin/python2.7" et "/usr/bin/python3.4 ") | ||
- | |||
- | <code root>update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1</code> | ||
- | <code root>update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2</code> | ||
- | |||
- | - Pour voir la nouvelle liste de update-alternatives : | ||
- | |||
- | <code root>update-alternatives --list python</code> | ||
- | <code retour> /usr/bin/python2.7 | ||
- | /usr/bin/python3.4</code> | ||
- | |||
- | |||
- | - On va laisser tout le système configurer avec python3 dans un premier temps : | ||
- | |||
- | <code root>update-alternatives --config python</code> | ||
- | <code retour> | ||
- | Il existe 2 choix pour l'alternative python (qui fournit /usr/bin/python). | ||
- | |||
- | Sélection Chemin Priorité État | ||
- | ------------------------------------------------------------ | ||
- | * 0 /usr/bin/python3.4 2 mode automatique | ||
- | 1 /usr/bin/python2.7 1 mode manuel | ||
- | 2 /usr/bin/python3.4 2 mode manuel | ||
- | |||
- | Appuyez sur <Entrée> pour conserver la valeur par défaut[*] ou choisissez le num | ||
- | </code> | ||
- | |||
- | On choisit la sélection correspondante à python2.7 pour tout le système. Ici c'est le choix n°1. | ||
- | |||
- | <note warning> | ||
- | * À savoir pour supprimer l'un des choix de la liste : | ||
- | |||
- | <code root>update-alternatives --remove python /usr/bin/python2.7</code> | ||
- | |||
- | * Ne jamais désinstaller les versions inférieures à python 3 ! \\ De nombreux logiciels ne fonctionneraient plus. | ||
- | |||
- | ''<del>apt-get purge python</del>'' | ||
- | </note> | ||
- | |||
- | * Pour vérifier | ||
- | |||
- | <code root>python --version</code> | ||
- | <code retour>Python 2.7.9</code> | ||
- | |||
- | <note tip> | ||
- | L'idée suivie ici sera de conserver python2 pour tout le système, et de mettre en place python3 dans un environnement virtuel consacré aux projets django. \\ | ||
- | |||
- | Pour installer Django avec python3 y compris **dans un environnement virtuel on n'utilisera pas** ''virtualenv'', afin de s'éviter quelque conflits lors de l'installation de django. \\ | ||
- | |||
- | En effet : | ||
- | |||
- | <code user> | ||
- | python --version | ||
- | </code> | ||
- | <code retour> | ||
- | Python 3.4.2 | ||
- | </code> | ||
- | |||
- | <code user>virtualenv MonPy3Django -p /usr/bin/python3.4</code> | ||
- | <code user>cd MonPy3Django/</code> | ||
- | <code user>source bin/activate 1.8-3.4</code> | ||
- | <code retour>Downloading/unpacking django | ||
- | Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded | ||
- | Installing collected packages: django | ||
- | *** Error compiling '/tmp/pip-build-c20d1nfa/django/django/conf/app_template/apps.py'... | ||
- | File "/tmp/pip-build-c20d1nfa/django/django/conf/app_template/apps.py", line 4 | ||
- | class {{ camel_case_app_name }}Config(AppConfig): | ||
- | ^ | ||
- | SyntaxError: invalid syntax | ||
- | |||
- | *** Error compiling '/tmp/pip-build-c20d1nfa/django/django/conf/app_template/models.py'... | ||
- | File "/tmp/pip-build-c20d1nfa/django/django/conf/app_template/models.py", line 1 | ||
- | {{ unicode_literals }}from django.db import models | ||
- | ^ | ||
- | SyntaxError: invalid syntax | ||
- | |||
- | Successfully installed django | ||
- | Cleaning up... | ||
- | </code> | ||
- | |||
- | </note> | ||
- | |||
- | |||
- | |||
- | |||
- | ===Configurer son système avec Python3 pour l'utilisateur courant :=== | ||
- | |||
- | * On édite le fichier "~/bashrc" : | ||
- | |||
- | <code user>vim ~/.bashrc</code> | ||
- | |||
- | * On ajoute cet alias : | ||
- | |||
- | <code> | ||
- | alias python='/usr/bin/python3.4' | ||
- | </code> | ||
- | |||
- | * On enregistre puis on actualise l'environnement de l'utilisateur courant : | ||
- | |||
- | <code user>. ~/.bashrc</code> | ||
- | |||
- | <code user>python --version</code> | ||
- | |||
- | <code retour>Python 3.4.2</code> | ||