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 !
Sur Jessie python et python 3 sont tous deux installés.
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 tree
update-alternatives --list python
update-alternatives: error: no alternatives for python
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
(ici par exemple; “/usr/bin/python2.7” et “/usr/bin/python3.4 ”)
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
- Pour voir la nouvelle liste de update-alternatives :
update-alternatives --list python
/usr/bin/python2.7 /usr/bin/python3.4
- On va laisser tout le système configurer avec python3 dans un premier temps :
update-alternatives --config python
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
On choisit la sélection correspondante à python2.7 pour tout le système. Ici c'est le choix n°1.
update-alternatives --remove python /usr/bin/python2.7
apt-get purge python
python --version
Python 2.7.9
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 :
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...
vim ~/.bashrc
alias python='/usr/bin/python3.4'
. ~/.bashrc
python --version
Python 3.4.2
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
virtualenv MonPy3Django -p /usr/bin/python3.4
Cela a crée une dossier nommé “PremiersProjetsDjango” dans le répertoire de l'utilisateur courant
cd ~/MonPy3Django/ && ls
Il contient trois dossiers permettant d'utiliser python :
bin include lib
Les outils sont dans bin/
tree bin/
bin/ ├── activate ├── activate.csh ├── activate.fish ├── activate_this.py ├── easy_install ├── easy_install-3.4 ├── pip ├── pip3 ├── pip3.4 ├── python -> python3.4 ├── python3 -> python3.4 └── python3.4
On voit que tout l'environnement pointe vers python3.4
deactivate
pip3 install django
(selon la méthode proposer par la doc officielle de Django : https://docs.djangoproject.com/fr/1.8/intro/tutorial01/)
python3 -c "import django; print(django.get_version())"
1.9
deactivate
python3 -c "import django; print(django.get_version())"
Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named 'django'
source bin/activate
python3 -c "import django; print(django.get_version())"
1.9
pip freeze
Django==1.9 wheel==0.24.0
À partir de là pour créer un projet Django, il faut aller dans le dossier de l'environnement virtuel python et activer python :
cd ~/Bureau/PremiersProjetsDjango/
source bin/activate
python3 -c "import django; print(django.get_version())"
pwd
/home/hypathie/Bureau/PremiersProjetsDjango
ls
bin include lib
django-admin.py startproject premierProjet
ls
bin include lib premierProjet
cd premierProjet/
manage.py premierProjet
cd premierProjet/
__init__.py settings.py urls.py wsgi.py
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