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 installer Django avec python3 y compris dans un environnement virtuel on n'utilisera pas virtualenv
seul, 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
* les commandes pyenv
pyenv +lacommande
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
- Pour que le shell 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 changer de version de python pour l'environnement virtuel, on fait la même chose avec la version 3
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
Ces fichiers sont :
Pour plus de détails voir la doc officielle de Django : https://docs.djangoproject.com/fr/1.8/intro/tutorial01/
cd ~/Bureau/PremiersProjetsDjango/premierProjet/
python3 manage.py runserver
Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. December 03, 2015 - 12:43:53 Django version 1.9, using settings 'premierProjet.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
On obtient :
~/Bureau/PremiersProjetsDjango/premierProjet/premierProjet
vim settings.py
... DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } ...
LANGUAGE_CODE = 'fr-fr' TIME_ZONE = 'Europe/Paris'
tree . ├── 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
python3 manage.py migrate
Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying sessions.0001_initial... OK
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
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
cd ~/Bureau/PremiersProjetsDjango/premierProjet
python3 manage.py startapp polls
Cela a crée le répertoire polls à la racine du dossier consacré au projet django :
pwd
/home/hypathie/Bureau/PremiersProjetsDjango/premierProjet
tree
. ├── db.sqlite3 ├── manage.py ├── polls │ ├── admin.py │ ├── apps.py │ ├── __init__.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── __init__.py │ │ └── __pycache__ │ │ ├── 0001_initial.cpython-34.pyc │ │ └── __init__.cpython-34.pyc │ ├── models.py │ ├── __pycache__ │ │ ├── admin.cpython-34.pyc │ │ ├── __init__.cpython-34.pyc │ │ └── models.cpython-34.pyc │ ├── tests.py │ └── views.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
vim polls/models.py
import datetime from django.db import models from django.utils import timezone # Create your models here. class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) class Choice(models.Model): question = models.ForeignKey(Question) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) def __str__(self): return self.choice_text
python3 manage.py makemigrations polls
Migrations for 'polls': 0001_initial.py: - Create model Choice - Create model Question - Add field question to choice
python3 manage.py sqlmigrate polls 0001
python3 manage.py migrate
python3 manage.py shell
cd ~/Bureau/PremiersProjetsDjango/premierProjet/
python3 manage.py createsuperuser
Username (leave blank to use 'hypathie'): Hypathie Email address: hypathie@gmx.fr Password: Password (again): Superuser created successfully.
python3 manage.py runserver 192.168.0.26:8000
Pour le savoir :
ifconfig
192.168.0.26:8000/admin
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