Wiki
Version 47 (Etienne Pallier, 03/18/2016 10:57 am) → Version 48/350 (Etienne Pallier, 03/18/2016 10:58 am)
h1. Technical Documentation for the PYROS project (FGFT-CC)
HOWTO Format Redmine Wiki : http://www.redmine.org/projects/redmine/wiki/FrRedmineWikiFormatting
{{>toc}}
---
h2. %{margin-left:0px; font-weight:bold; font-size:25px; display:block; color:red;}I - INSTALLATION%
h3. Create database
One liner:
$ mysql -u root < pyros.sql
Or :
$ mysql -u root
mysql> create database pyros;
mysql> use pyros;
mysql> source pyros.sql;
(
TODO:
mysql> grant all on pyros.* to pyros@localhost identified by ‘pyros’;)
mysql> flush privileges;
)
---
h3. Install python3.5
* Mac OS X :
<pre>
1) Installer MacPort
(TODO: doc)
2) Installer le "port" python35
$ sudo port install python35
</pre>
* Linux (Ubuntu) :
<pre>
$ sudo apt-get ...
</pre>
---
h3. Create project dir
$ mkdir pyros
---
h3. Create virtualenv with python3.5 dedicated to pyros project
$ cd pyros/
$ which python3.5
/opt/local/bin/python3.5
$ virtualenv-3.5 venv_py35_pyros -p /opt/local/bin/python3.5
=> creates a venv_py35_pyros/ folder inside pyros/
---
h3. Activate venv
$ source venv_py35_pyros/bin/activate
$ python -V
Python 3.5.1
$ which pip
…/pyros/venv_py35_pyros/bin/pip
Upgrade pip to last version available :
$ pip install --upgrade pip
Collecting pip
Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
Installing collected packages: pip
Found existing installation: pip 7.1.2
Uninstalling pip-7.1.2:
Successfully uninstalled pip-7.1.2
Successfully installed pip-8.1.1
h3. Install needed python packages (from within the virtual environment)
*Install Django* :
<pre>
$ pip install django
Collecting django
Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
Installing collected packages: django
Successfully installed django-1.9.4
$ pip install django-admin-tools
Collecting django-admin-tools
Downloading django_admin_tools-0.7.2-py2.py3-none-any.whl (289kB)
Installing collected packages: django-admin-tools
Successfully installed django-admin-tools-0.7.2
$ pip install django-debug-toolbar
Collecting django-debug-toolbar
Downloading django_debug_toolbar-1.4-py2.py3-none-any.whl (212kB)
Requirement already satisfied (use --upgrade to upgrade): Django>=1.7 in ./venv_py35_pyros/lib/python3.5/site-packages (from django-debug-toolbar)
Collecting sqlparse (from django-debug-toolbar)
Downloading sqlparse-0.1.19.tar.gz (58kB)
Building wheels for collected packages: sqlparse
Running setup.py bdist_wheel for sqlparse ... done
Stored in directory: /Users/epallier/Library/Caches/pip/wheels/7b/d4/72/6011bb100dd5fc213164e4bbee13d4e03261dd54ce6a5de6b8
Successfully built sqlparse
Installing collected packages: sqlparse, django-debug-toolbar
Successfully installed django-debug-toolbar-1.4 sqlparse-0.1.19
$ pip install django-extensions
Collecting django-extensions
Downloading django_extensions-1.6.1-py2.py3-none-any.whl (202kB)
Collecting six>=1.2 (from django-extensions)
Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, django-extensions
Successfully installed django-extensions-1.6.1 six-1.10.0
$ pip install django-suit
Collecting django-suit
Downloading django-suit-0.2.18.tar.gz (587kB)
Building wheels for collected packages: django-suit
Running setup.py bdist_wheel for django-suit ... done
Stored in directory: /Users/epallier/Library/Caches/pip/wheels/12/8b/9a/e02ab0ad9229881638aa040d47d77c8f562999533811927d41
Successfully built django-suit
Installing collected packages: django-suit
Successfully installed django-suit-0.2.18
</pre>
*Install the web application server gunicorn (will be used in production instead of the dev django web server)* :
<pre>
$ pip install gunicorn
Collecting gunicorn
Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
Installing collected packages: gunicorn
Successfully installed gunicorn-19.4.5
</pre>
*Install the python mysql client*:
<pre>
$ pip install mysqlclient
...
</pre>
=> Issue under Mac OS X:
<pre>
Collecting mysqlclient
Downloading mysqlclient-1.3.7.tar.gz (79kB)
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient ... error
…
----------------------------------------
Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.3.7
BOUH !!!
$ pip install --upgrade wheel
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
Installing collected packages: wheel
Found existing installation: wheel 0.24.0
Uninstalling wheel-0.24.0:
Successfully uninstalled wheel-0.24.0
Successfully installed wheel-0.29.0
$ pip uninstall mysqlclient
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.7.tar.gz
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient ... done
Stored in directory: /Users/epallier/Library/Caches/pip/wheels/9b/06/50/d11418c26cf8f2156b13d4363b5afde8e7e75ebb8540d0228d
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.7
YES !!!
</pre>
---
h3. Project organization
Example of a good organization :
1 project = N applis
(but 1 appli can be part of many projects)
(then 1 appli = N models)
<pre>
MYPROJECT/
src/
myproject/
appli1/
appli2/
…
appliN/
public/
static/
private/
requirements.txt
</pre>
Set needed folders:
<pre>
$ cd pyros/
$ mkdir private public
$ mkdir public/static
</pre>
---
h3. Create Django project pyros
<pre>
$ cd pyros/
$ django-admin startproject pyros
$ tree pyros/
pyros/
├── manage.py
└── pyros
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
$ mv pyros src
$ cd src/
$ ./manage.py runserver
(or gunicorn pyros.wsgi)
==> http://localhost:8000
</pre>
---
h3. Set Database engine as MySql
Edit src/pyros/settings.py
<pre>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'pyros',
'USER': 'root',
'PASSWORD': ''
}
}
</pre>
---
h3. Import database into Django (with inspectdb)
$ cd src/
$ ./manage.py inspectdb > models.py
*Issue on Mac OS X*:
<pre>
Traceback (most recent call last):
File "/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 25, in <module>
import MySQLdb as Database
File "/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
Reason: image not found
=> BOUH !!!
LA SOLUTION EST ICI : http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib
(
Apparemment, ceci aurait dû suffire:
mkdir -p /usr/local/lib
ln -s /usr/local/mysql/lib/libmysql* /usr/local/lib
)
Mais j’ai fait ceci:
$ otool -L /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
...
$ locate libmysqlclient.18.dylib
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
/Library/SystemMigration/History/Migration-68137DFB-CB6A-4FBB-81E2-11BDB5D01E48/QuarantineRoot/usr/lib/libmysqlclient.18.dylib
$ sudo install_name_tool -change libmysqlclient.18.dylib /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
$ otool -L /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
...
$ ./manage.py inspectdb > models.py
=> YES !!!
</pre>
---
h3. Create a Django django application pyrosapp
$ ./manage.py startapp pyrosapp
$ tree src
src
├── manage.py
├── pyros
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-35.pyc
│ │ ├── settings.cpython-35.pyc
│ │ ├── urls.cpython-35.pyc
│ │ └── wsgi.cpython-35.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── pyrosapp
├── __init__.py
├── admin.py
├── apps.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
---
h3. Replace the default pyrosapp models.py with the inspectdb generated one
$ mv models.py pyrosapp/
---
h3. *TODO: Fix and improve the inspectdb generated file models.py*
$ cd pyrosapp/
$ vi models.py
HOWTO Format Redmine Wiki : http://www.redmine.org/projects/redmine/wiki/FrRedmineWikiFormatting
{{>toc}}
---
h2. %{margin-left:0px; font-weight:bold; font-size:25px; display:block; color:red;}I - INSTALLATION%
h3. Create database
One liner:
$ mysql -u root < pyros.sql
Or :
$ mysql -u root
mysql> create database pyros;
mysql> use pyros;
mysql> source pyros.sql;
(
TODO:
mysql> grant all on pyros.* to pyros@localhost identified by ‘pyros’;)
mysql> flush privileges;
)
---
h3. Install python3.5
* Mac OS X :
<pre>
1) Installer MacPort
(TODO: doc)
2) Installer le "port" python35
$ sudo port install python35
</pre>
* Linux (Ubuntu) :
<pre>
$ sudo apt-get ...
</pre>
---
h3. Create project dir
$ mkdir pyros
---
h3. Create virtualenv with python3.5 dedicated to pyros project
$ cd pyros/
$ which python3.5
/opt/local/bin/python3.5
$ virtualenv-3.5 venv_py35_pyros -p /opt/local/bin/python3.5
=> creates a venv_py35_pyros/ folder inside pyros/
---
h3. Activate venv
$ source venv_py35_pyros/bin/activate
$ python -V
Python 3.5.1
$ which pip
…/pyros/venv_py35_pyros/bin/pip
Upgrade pip to last version available :
$ pip install --upgrade pip
Collecting pip
Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
Installing collected packages: pip
Found existing installation: pip 7.1.2
Uninstalling pip-7.1.2:
Successfully uninstalled pip-7.1.2
Successfully installed pip-8.1.1
h3. Install needed python packages (from within the virtual environment)
*Install Django* :
<pre>
$ pip install django
Collecting django
Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
Installing collected packages: django
Successfully installed django-1.9.4
$ pip install django-admin-tools
Collecting django-admin-tools
Downloading django_admin_tools-0.7.2-py2.py3-none-any.whl (289kB)
Installing collected packages: django-admin-tools
Successfully installed django-admin-tools-0.7.2
$ pip install django-debug-toolbar
Collecting django-debug-toolbar
Downloading django_debug_toolbar-1.4-py2.py3-none-any.whl (212kB)
Requirement already satisfied (use --upgrade to upgrade): Django>=1.7 in ./venv_py35_pyros/lib/python3.5/site-packages (from django-debug-toolbar)
Collecting sqlparse (from django-debug-toolbar)
Downloading sqlparse-0.1.19.tar.gz (58kB)
Building wheels for collected packages: sqlparse
Running setup.py bdist_wheel for sqlparse ... done
Stored in directory: /Users/epallier/Library/Caches/pip/wheels/7b/d4/72/6011bb100dd5fc213164e4bbee13d4e03261dd54ce6a5de6b8
Successfully built sqlparse
Installing collected packages: sqlparse, django-debug-toolbar
Successfully installed django-debug-toolbar-1.4 sqlparse-0.1.19
$ pip install django-extensions
Collecting django-extensions
Downloading django_extensions-1.6.1-py2.py3-none-any.whl (202kB)
Collecting six>=1.2 (from django-extensions)
Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, django-extensions
Successfully installed django-extensions-1.6.1 six-1.10.0
$ pip install django-suit
Collecting django-suit
Downloading django-suit-0.2.18.tar.gz (587kB)
Building wheels for collected packages: django-suit
Running setup.py bdist_wheel for django-suit ... done
Stored in directory: /Users/epallier/Library/Caches/pip/wheels/12/8b/9a/e02ab0ad9229881638aa040d47d77c8f562999533811927d41
Successfully built django-suit
Installing collected packages: django-suit
Successfully installed django-suit-0.2.18
</pre>
*Install the web application server gunicorn (will be used in production instead of the dev django web server)* :
<pre>
$ pip install gunicorn
Collecting gunicorn
Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
Installing collected packages: gunicorn
Successfully installed gunicorn-19.4.5
</pre>
*Install the python mysql client*:
<pre>
$ pip install mysqlclient
...
</pre>
=> Issue under Mac OS X:
<pre>
Collecting mysqlclient
Downloading mysqlclient-1.3.7.tar.gz (79kB)
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient ... error
…
----------------------------------------
Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.3.7
BOUH !!!
$ pip install --upgrade wheel
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
Installing collected packages: wheel
Found existing installation: wheel 0.24.0
Uninstalling wheel-0.24.0:
Successfully uninstalled wheel-0.24.0
Successfully installed wheel-0.29.0
$ pip uninstall mysqlclient
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.7.tar.gz
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient ... done
Stored in directory: /Users/epallier/Library/Caches/pip/wheels/9b/06/50/d11418c26cf8f2156b13d4363b5afde8e7e75ebb8540d0228d
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.7
YES !!!
</pre>
---
h3. Project organization
Example of a good organization :
1 project = N applis
(but 1 appli can be part of many projects)
(then 1 appli = N models)
<pre>
MYPROJECT/
src/
myproject/
appli1/
appli2/
…
appliN/
public/
static/
private/
requirements.txt
</pre>
Set needed folders:
<pre>
$ cd pyros/
$ mkdir private public
$ mkdir public/static
</pre>
---
h3. Create Django project pyros
<pre>
$ cd pyros/
$ django-admin startproject pyros
$ tree pyros/
pyros/
├── manage.py
└── pyros
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
$ mv pyros src
$ cd src/
$ ./manage.py runserver
(or gunicorn pyros.wsgi)
==> http://localhost:8000
</pre>
---
h3. Set Database engine as MySql
Edit src/pyros/settings.py
<pre>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'pyros',
'USER': 'root',
'PASSWORD': ''
}
}
</pre>
---
h3. Import database into Django (with inspectdb)
$ cd src/
$ ./manage.py inspectdb > models.py
*Issue on Mac OS X*:
<pre>
Traceback (most recent call last):
File "/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 25, in <module>
import MySQLdb as Database
File "/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
Reason: image not found
=> BOUH !!!
LA SOLUTION EST ICI : http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib
(
Apparemment, ceci aurait dû suffire:
mkdir -p /usr/local/lib
ln -s /usr/local/mysql/lib/libmysql* /usr/local/lib
)
Mais j’ai fait ceci:
$ otool -L /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
...
$ locate libmysqlclient.18.dylib
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
/Library/SystemMigration/History/Migration-68137DFB-CB6A-4FBB-81E2-11BDB5D01E48/QuarantineRoot/usr/lib/libmysqlclient.18.dylib
$ sudo install_name_tool -change libmysqlclient.18.dylib /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
$ otool -L /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
...
$ ./manage.py inspectdb > models.py
=> YES !!!
</pre>
---
h3. Create a Django django application pyrosapp
$ ./manage.py startapp pyrosapp
$ tree src
src
├── manage.py
├── pyros
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-35.pyc
│ │ ├── settings.cpython-35.pyc
│ │ ├── urls.cpython-35.pyc
│ │ └── wsgi.cpython-35.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── pyrosapp
├── __init__.py
├── admin.py
├── apps.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
---
h3. Replace the default pyrosapp models.py with the inspectdb generated one
$ mv models.py pyrosapp/
---
h3. *TODO: Fix and improve the inspectdb generated file models.py*
$ cd pyrosapp/
$ vi models.py