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 →
Ceci est une ancienne révision du document !
Installer les outils et bibliothèques pour développer en python ou python3
apt-get install python-dev python3-dev
apt-get install libblas3 libblas-dev liblapack3 liblapack-dev
apt-get install libfreetype6 libfreetype6-dev
apt-get install libffi-dev libssl-dev
apt-get install python-pip python3-pip
apt-get install python-virtualenv
apt-get install python3-virtualenv
En effet, avec la commande apt-get install python-virtualenv
a installé python3-virtualenv
et python-virtualenv
python3-pip
(ou python-pip
) : installateur de paquets python, Pip permet d'installer aisément des modules Python, à la manière dont on installe des paquets dans une distribution linux;python3-dev
(ou python-dev
): permet d'utiliser des outils de développement pour la construction des modules Python, non pris en charge par pip, en particulier pour utiliser des bibliothèques avec des extensions en C virtualenv
: permet de créer un environnement cloisonné Python apt-get install python-doc python3-doc
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev
apt-get install tree
ls /usr/bin/python*
/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
Pour ce faire, on va créer un environnement virtuel dans un dossier créé dans le repertoire courant de l'utilisateur du système.
On pourra alors installer Django aussi bien pour y coder en python2 qu'en python3, sans se soucier de la version mise en place sur l'ensemble du système.
Cela évitera aussi de se mélanger les pinceaux entre les utilitaires pip install …
ou pip3 install …
.
On n'utilisera pas virtualenv
seul, mais on l'utilisera avec pyenv
afin de s'éviter quelque conflits lors de l'installation de django.
En effet :
python --version
Python 3.4.2
virtualenv MonPy3Django -p /usr/bin/python3.4
cd MonPy3Django/
source bin/activate 1.8-3.4
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...
rm -r ~/MonPy3Django
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec $SHELL
pyenv
pyenv 20151124-16-g132179d Usage: pyenv <command> [<args>] Some useful pyenv commands are: commands List all available pyenv commands local Set or show the local application-specific Python version global Set or show the global Python version shell Set or show the shell-specific Python version install Install a Python version using python-build uninstall Uninstall a specific Python version rehash Rehash pyenv shims (run this after installing executables) version Show the current Python version and its origin versions List all Python versions available to pyenv which Display the full path to an executable whence List all Python versions that contain the given executable See `pyenv help <command>' for information on a specific command. For full documentation, see: https://github.com/yyuu/pyenv#readme
pyenv install 2.7.9
pyenv install 3.4.3
pyenv versions
* system (set by /home/hypathie/.pyenv/version) 2.7.9 3.4.3
pyenv
Some useful pyenv commands are: commands List all available pyenv commands local Set or show the local application-specific Python version global Set or show the global Python version shell Set or show the shell-specific Python version install Install a Python version using python-build uninstall Uninstall a specific Python version rehash Rehash pyenv shims (run this after installing executables) version Show the current Python version and its origin versions List all Python versions available to pyenv which Display the full path to an executable whence List all Python versions that contain the given executable
pyenv +lacommande
- Pour que le shell de pyenv utilise la version 2 (installée plutôt)
pyenv shell 2.7.9
- Pour savoir quelle est la version de son shell
pyenv shell
2.7.9
- version de python utilisée
python --version
Python 2.7.9
- Depuis où ?
which python
/home/hypathie/.pyenv/shims/python
- Pour que le shell de pyenv utilise la version 3 (installée aussi plutôt)
pyenv shell 3.4.3
python --version
Python 3.4.3
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
exec $SHELL
mkdir ProjetsDjangoPy3 && cd ProjetsDjangoPy3
pyenv shell 3.4.3
python --version
Python 3.4.3
pyenv virtualenv 1.8-3.4
Ignoring indexes: https://pypi.python.org/simple Requirement already satisfied (use --upgrade to upgrade): setuptools in /home/hypathie/.pyenv/versions/3.4.3/envs/1.8-3.4/lib/python3.4/site-packages Requirement already satisfied (use --upgrade to upgrade): pip in /home/hypathie/.pyenv/versions/3.4.3/envs/1.8-3.4/lib/python3.4/site-packages
pyenv activate 1.8-3.4
pip install django
You are using pip version 6.0.8, however version 7.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting django Downloading Django-1.9-py2.py3-none-any.whl (6.6MB) 100% |################################| 6.6MB 88kB/s Installing collected packages: django Successfully installed django-1.9 (1.8-3.4) hypathie@debian:~/MonPython3Django$ pip install django
Pas d'erreur cette fois
django-admin.py --version
1.9
python --version
Python 3.4.3
Avec la commande recommandée par la doc officielle de django:
python3 -c "import django; print(django.get_version())"
aussi bien que :
python -c "import django; print(django.get_version())"
1.9
pyenv deactivate
pyenv deactivate
cd ~/ProjetsDjangoPy3/
pyenv activate 1.8-3.4
django-admin.py startproject premierProjet
tree premierProjet/
premierProjet/ ├── manage.py └── premierProjet ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py
https://docs.djangoproject.com/fr/1.8/intro/tutorial01/
Notre avantage, on peut aussi bien lancer à la place des deux commandes suivantes :
python manage.py migrate
python manage.py runserver
que celles-ci
python3 manage.py migrate
python3 manage.py runserver
python manage.py migrate
a créé le fichier db.sqlite3
tree
. ├── db.sqlite3 ├── manage.py └── premierProjet ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-34.pyc │ ├── settings.cpython-34.pyc │ ├── urls.cpython-34.pyc │ └── wsgi.cpython-34.pyc ├── settings.py ├── urls.py └── wsgi.py
~/Bureau/PremiersProjetsDjango/premierProjet/premierProjet
vim settings.py
... DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } ...
settings.py
:LANGUAGE_CODE = 'fr-fr' TIME_ZONE = 'Europe/Paris'
python manage.py migrate
a ajouté au fichier “settings.py ” dans la section “INSTALLED_APPS” la ligne : 'polls',
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls', )
python3 manage.py makemigrations
No changes detected
Après avoir lancé la commande python manage.py runserver
on inscrit dans son navigateur on entre dans la barre url: “http://localhost:8000/”
apt-get install curl
apt-get install git-core
Voir : https://github.com/search?utf8=%E2%9C%93&q=pathogen
mkdir -p ~/.vim/autoload ~/.vim/bundle && \ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
vim ~/.vimrc
execute pathogen#infect() syntax on filetype plugin indent on
pathogen va chercher dans le répertoire bundle les plugin qu'on lui a installé et les utiliser comme si on les avait installé dans le fichier .vimrc
Voir : https://github.com/scrooloose/nerdtree
git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
t: Ouvrir le fichier sélectionné dans un nouvel onglet i: Ouvrez le fichier sélectionné dans une fenêtre fissure verticale s: Open the selected file in a vertical split window I: Commutation de fichiers cachés m: Pour faire apparaître un menu qui vous permettra d'ajouter rapidement, déplacer(=renomer), copier et supprimer des nœuds (ou fichiers). R: Actualiser l'arbre, utile si les fichiers ont changés en dehors de Vim ?: Commutation entre l'aide rapide et l'explorateur NERD Tree Ctrl +w puis w: Passer de l'explorateur NERD Tree à la fenêtre d'édition des fichiers
git clone https://github.com/bling/vim-airline.git ~/.vim/bundle/vim-airline
On ajoute la ligne suivante dans ~./vimrc
:
let g:airline#extensions#tabline#enabled = 1
:register
puis on choisit son buffer ;:bn
(pour Buffer Next) ou :bp
(pour Buffer Prevous) ;~/.vimrc
nmap <C-n> :bn<CR> nmap <C-p> :bp<CR>
set mouse=a
On édite ~/.vimrc
On ajoute :
set mouse=a
Voir : https://github.com/scrooloose/syntastic
git clone https://github.com/scrooloose/syntastic.git ~/.vim/bundle/syntastic
git clone https://github.com/majutsushi/tagbar.git ~/.vim/bundle/tagbar
~/.vimrc
"Racourci clavier pour basculer avec Tagbar nmap <F2> :TagbarToggle<CR>
~/.vimrc
"Pour utiliser un plugin d'autocomplétion set omnifunc=syntaxComplet#Complete