Wiki

Version 39 (Etienne Pallier, 03/18/2016 10:49 am)

1 1 Etienne Pallier
h1. Technical Documentation for the PYROS project (FGFT-CC)
2 1 Etienne Pallier
3 1 Etienne Pallier
4 1 Etienne Pallier
HOWTO Format Redmine Wiki : http://www.redmine.org/projects/redmine/wiki/FrRedmineWikiFormatting
5 1 Etienne Pallier
6 1 Etienne Pallier
{{>toc}}
7 1 Etienne Pallier
8 1 Etienne Pallier
9 1 Etienne Pallier
10 3 Etienne Pallier
---
11 1 Etienne Pallier
12 17 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}I - INSTALLATION%
13 2 Etienne Pallier
14 2 Etienne Pallier
15 1 Etienne Pallier
16 6 Etienne Pallier
h3. Create database
17 1 Etienne Pallier
18 3 Etienne Pallier
One liner:
19 3 Etienne Pallier
$ mysql -u root < pyros.sql
20 1 Etienne Pallier
21 3 Etienne Pallier
Or :
22 3 Etienne Pallier
$ mysql -u root
23 3 Etienne Pallier
mysql> create database pyros;
24 3 Etienne Pallier
mysql> use pyros;
25 3 Etienne Pallier
mysql> source pyros.sql;
26 1 Etienne Pallier
27 3 Etienne Pallier
(
28 3 Etienne Pallier
TODO:
29 3 Etienne Pallier
mysql> grant all on pyros.* to pyros@localhost identified by ‘pyros’;)
30 3 Etienne Pallier
mysql> flush privileges;
31 3 Etienne Pallier
)
32 1 Etienne Pallier
33 1 Etienne Pallier
34 1 Etienne Pallier
35 4 Etienne Pallier
---
36 5 Etienne Pallier
37 6 Etienne Pallier
h3. Install python3.5
38 1 Etienne Pallier
39 11 Etienne Pallier
40 11 Etienne Pallier
 * Mac OS X :
41 23 Etienne Pallier
<pre>
42 24 Etienne Pallier
1) Installer MacPort
43 24 Etienne Pallier
(TODO: doc)
44 24 Etienne Pallier
45 24 Etienne Pallier
2) Installer le "port" python35
46 1 Etienne Pallier
$ sudo port install python35
47 23 Etienne Pallier
</pre>
48 1 Etienne Pallier
49 11 Etienne Pallier
 * Linux (Ubuntu) :
50 23 Etienne Pallier
<pre>
51 1 Etienne Pallier
$ sudo apt-get ...
52 23 Etienne Pallier
</pre>
53 1 Etienne Pallier
54 5 Etienne Pallier
55 3 Etienne Pallier
56 4 Etienne Pallier
---
57 5 Etienne Pallier
58 13 Etienne Pallier
h3. Create project dir
59 13 Etienne Pallier
60 13 Etienne Pallier
$ mkdir pyros
61 13 Etienne Pallier
62 13 Etienne Pallier
63 13 Etienne Pallier
---
64 13 Etienne Pallier
65 14 Etienne Pallier
h3. Create virtualenv with python3.5 dedicated to pyros project
66 3 Etienne Pallier
67 3 Etienne Pallier
$ cd pyros/
68 3 Etienne Pallier
69 3 Etienne Pallier
$ which python3.5
70 3 Etienne Pallier
/opt/local/bin/python3.5
71 3 Etienne Pallier
72 15 Etienne Pallier
$ virtualenv-3.5 venv_py35_pyros -p /opt/local/bin/python3.5
73 3 Etienne Pallier
=> creates a venv_py35_pyros/ folder inside pyros/
74 3 Etienne Pallier
75 1 Etienne Pallier
76 1 Etienne Pallier
77 7 Etienne Pallier
---
78 3 Etienne Pallier
79 16 Etienne Pallier
h3. Activate venv
80 7 Etienne Pallier
81 3 Etienne Pallier
$ source venv_py35_pyros/bin/activate
82 3 Etienne Pallier
83 3 Etienne Pallier
$ python -V
84 3 Etienne Pallier
Python 3.5.1
85 3 Etienne Pallier
86 3 Etienne Pallier
$ which pip
87 1 Etienne Pallier
…/pyros/venv_py35_pyros/bin/pip
88 16 Etienne Pallier
89 18 Etienne Pallier
Upgrade pip to last version available :
90 3 Etienne Pallier
91 3 Etienne Pallier
$ pip install --upgrade pip
92 3 Etienne Pallier
Collecting pip
93 3 Etienne Pallier
  Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
94 3 Etienne Pallier
Installing collected packages: pip
95 3 Etienne Pallier
  Found existing installation: pip 7.1.2
96 3 Etienne Pallier
    Uninstalling pip-7.1.2:
97 3 Etienne Pallier
      Successfully uninstalled pip-7.1.2
98 1 Etienne Pallier
Successfully installed pip-8.1.1
99 18 Etienne Pallier
100 27 Etienne Pallier
h3. Install needed python packages (from within the virtual environment)
101 18 Etienne Pallier
102 3 Etienne Pallier
103 33 Etienne Pallier
*Install Django* :
104 32 Etienne Pallier
105 32 Etienne Pallier
<pre>
106 3 Etienne Pallier
$ pip install django
107 3 Etienne Pallier
Collecting django
108 3 Etienne Pallier
  Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
109 3 Etienne Pallier
Installing collected packages: django
110 3 Etienne Pallier
Successfully installed django-1.9.4
111 3 Etienne Pallier
112 3 Etienne Pallier
$ pip install django-admin-tools
113 3 Etienne Pallier
Collecting django-admin-tools
114 3 Etienne Pallier
  Downloading django_admin_tools-0.7.2-py2.py3-none-any.whl (289kB)
115 3 Etienne Pallier
Installing collected packages: django-admin-tools
116 3 Etienne Pallier
Successfully installed django-admin-tools-0.7.2
117 3 Etienne Pallier
118 21 Etienne Pallier
$ pip install django-debug-toolbar
119 21 Etienne Pallier
Collecting django-debug-toolbar
120 21 Etienne Pallier
  Downloading django_debug_toolbar-1.4-py2.py3-none-any.whl (212kB)
121 21 Etienne Pallier
Requirement already satisfied (use --upgrade to upgrade): Django>=1.7 in ./venv_py35_pyros/lib/python3.5/site-packages (from django-debug-toolbar)
122 21 Etienne Pallier
Collecting sqlparse (from django-debug-toolbar)
123 21 Etienne Pallier
  Downloading sqlparse-0.1.19.tar.gz (58kB)
124 21 Etienne Pallier
Building wheels for collected packages: sqlparse
125 21 Etienne Pallier
  Running setup.py bdist_wheel for sqlparse ... done
126 21 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/7b/d4/72/6011bb100dd5fc213164e4bbee13d4e03261dd54ce6a5de6b8
127 21 Etienne Pallier
Successfully built sqlparse
128 21 Etienne Pallier
Installing collected packages: sqlparse, django-debug-toolbar
129 21 Etienne Pallier
Successfully installed django-debug-toolbar-1.4 sqlparse-0.1.19
130 21 Etienne Pallier
131 21 Etienne Pallier
$ pip install django-extensions
132 21 Etienne Pallier
Collecting django-extensions
133 21 Etienne Pallier
  Downloading django_extensions-1.6.1-py2.py3-none-any.whl (202kB)
134 21 Etienne Pallier
Collecting six>=1.2 (from django-extensions)
135 21 Etienne Pallier
  Downloading six-1.10.0-py2.py3-none-any.whl
136 21 Etienne Pallier
Installing collected packages: six, django-extensions
137 21 Etienne Pallier
Successfully installed django-extensions-1.6.1 six-1.10.0
138 21 Etienne Pallier
139 21 Etienne Pallier
$ pip install django-suit
140 21 Etienne Pallier
Collecting django-suit
141 21 Etienne Pallier
  Downloading django-suit-0.2.18.tar.gz (587kB)
142 21 Etienne Pallier
Building wheels for collected packages: django-suit
143 1 Etienne Pallier
  Running setup.py bdist_wheel for django-suit ... done
144 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/12/8b/9a/e02ab0ad9229881638aa040d47d77c8f562999533811927d41
145 1 Etienne Pallier
Successfully built django-suit
146 1 Etienne Pallier
Installing collected packages: django-suit
147 1 Etienne Pallier
Successfully installed django-suit-0.2.18
148 21 Etienne Pallier
149 32 Etienne Pallier
</pre>
150 32 Etienne Pallier
151 33 Etienne Pallier
*Install the web application server gunicorn (will be used in production instead of the dev django web server)* :
152 32 Etienne Pallier
<pre>
153 25 Etienne Pallier
$ pip install gunicorn
154 25 Etienne Pallier
Collecting gunicorn
155 25 Etienne Pallier
  Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
156 21 Etienne Pallier
Installing collected packages: gunicorn
157 26 Etienne Pallier
Successfully installed gunicorn-19.4.5
158 32 Etienne Pallier
</pre>
159 1 Etienne Pallier
160 33 Etienne Pallier
*Install the python mysql client*:
161 32 Etienne Pallier
<pre>
162 32 Etienne Pallier
$ pip install mysqlclient
163 32 Etienne Pallier
...
164 32 Etienne Pallier
</pre>
165 20 Etienne Pallier
166 33 Etienne Pallier
=> Issue under Mac OS X:
167 21 Etienne Pallier
<pre>
168 20 Etienne Pallier
169 3 Etienne Pallier
Collecting mysqlclient
170 3 Etienne Pallier
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
171 1 Etienne Pallier
Building wheels for collected packages: mysqlclient
172 22 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... error
173 3 Etienne Pallier
174 3 Etienne Pallier
  ----------------------------------------
175 1 Etienne Pallier
  Failed building wheel for mysqlclient
176 1 Etienne Pallier
  Running setup.py clean for mysqlclient
177 1 Etienne Pallier
Failed to build mysqlclient
178 1 Etienne Pallier
Installing collected packages: mysqlclient
179 1 Etienne Pallier
  Running setup.py install for mysqlclient ... done
180 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
181 1 Etienne Pallier
182 1 Etienne Pallier
BOUH !!!
183 1 Etienne Pallier
184 1 Etienne Pallier
$ pip install --upgrade wheel
185 1 Etienne Pallier
Collecting wheel
186 1 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
187 1 Etienne Pallier
Installing collected packages: wheel
188 1 Etienne Pallier
  Found existing installation: wheel 0.24.0
189 1 Etienne Pallier
    Uninstalling wheel-0.24.0:
190 1 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
191 1 Etienne Pallier
Successfully installed wheel-0.29.0
192 1 Etienne Pallier
193 1 Etienne Pallier
$ pip uninstall mysqlclient
194 1 Etienne Pallier
195 1 Etienne Pallier
$ pip install mysqlclient
196 1 Etienne Pallier
Collecting mysqlclient
197 1 Etienne Pallier
  Using cached mysqlclient-1.3.7.tar.gz
198 1 Etienne Pallier
Building wheels for collected packages: mysqlclient
199 1 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... done
200 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/9b/06/50/d11418c26cf8f2156b13d4363b5afde8e7e75ebb8540d0228d
201 1 Etienne Pallier
Successfully built mysqlclient
202 1 Etienne Pallier
Installing collected packages: mysqlclient
203 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
204 1 Etienne Pallier
205 1 Etienne Pallier
YES !!!
206 21 Etienne Pallier
</pre>
207 1 Etienne Pallier
208 1 Etienne Pallier
209 12 Etienne Pallier
210 12 Etienne Pallier
211 12 Etienne Pallier
---
212 12 Etienne Pallier
213 28 Etienne Pallier
h3. Project organization
214 12 Etienne Pallier
 
215 29 Etienne Pallier
Example of a good organization :
216 1 Etienne Pallier
217 29 Etienne Pallier
1 project = N applis
218 29 Etienne Pallier
(but 1 appli can be part of many projects)
219 30 Etienne Pallier
(then 1 appli = N models)
220 12 Etienne Pallier
221 31 Etienne Pallier
<pre>
222 34 Etienne Pallier
223 29 Etienne Pallier
MYPROJECT/
224 34 Etienne Pallier
225 1 Etienne Pallier
	src/
226 1 Etienne Pallier
		myproject/
227 34 Etienne Pallier
		appli1/
228 34 Etienne Pallier
		appli2/
229 12 Etienne Pallier
230 34 Etienne Pallier
		appliN/
231 34 Etienne Pallier
232 12 Etienne Pallier
	public/
233 34 Etienne Pallier
		static/
234 34 Etienne Pallier
235 12 Etienne Pallier
	private/
236 1 Etienne Pallier
		requirements.txt
237 1 Etienne Pallier
</pre>
238 1 Etienne Pallier
239 1 Etienne Pallier
240 37 Etienne Pallier
Set needed folders:
241 37 Etienne Pallier
<pre>
242 37 Etienne Pallier
$ cd pyros/
243 12 Etienne Pallier
$ mkdir private public
244 12 Etienne Pallier
$ mkdir public/static
245 37 Etienne Pallier
</pre>
246 3 Etienne Pallier
247 7 Etienne Pallier
---
248 3 Etienne Pallier
249 39 Etienne Pallier
h3. Create Django project pyros
250 7 Etienne Pallier
251 38 Etienne Pallier
<pre>
252 38 Etienne Pallier
$ cd pyros/
253 38 Etienne Pallier
254 3 Etienne Pallier
$ django-admin startproject pyros
255 3 Etienne Pallier
256 3 Etienne Pallier
$ tree pyros/
257 3 Etienne Pallier
pyros/
258 3 Etienne Pallier
├── manage.py
259 3 Etienne Pallier
└── pyros
260 3 Etienne Pallier
    ├── __init__.py
261 3 Etienne Pallier
    ├── settings.py
262 3 Etienne Pallier
    ├── urls.py
263 3 Etienne Pallier
    └── wsgi.py
264 3 Etienne Pallier
265 3 Etienne Pallier
$ mv pyros src
266 3 Etienne Pallier
267 3 Etienne Pallier
$ cd src/
268 3 Etienne Pallier
269 3 Etienne Pallier
$ ./manage.py runserver
270 1 Etienne Pallier
(ou gunicorn pyros.wsgi)
271 1 Etienne Pallier
==> http://localhost:8000
272 38 Etienne Pallier
</pre>
273 3 Etienne Pallier
274 3 Etienne Pallier
275 7 Etienne Pallier
---
276 3 Etienne Pallier
277 7 Etienne Pallier
h3. Set Database mysql
278 7 Etienne Pallier
279 3 Etienne Pallier
Edit src/pyros/settings.py
280 3 Etienne Pallier
281 3 Etienne Pallier
DATABASES = {
282 3 Etienne Pallier
    'default': {
283 3 Etienne Pallier
        'ENGINE': 'django.db.backends.mysql',
284 1 Etienne Pallier
        'NAME': 'pyros',
285 3 Etienne Pallier
        'USER': 'root',
286 1 Etienne Pallier
        'PASSWORD': ''
287 1 Etienne Pallier
    }
288 3 Etienne Pallier
}
289 3 Etienne Pallier
290 3 Etienne Pallier
291 7 Etienne Pallier
---
292 3 Etienne Pallier
293 7 Etienne Pallier
h3. Import database into django
294 7 Etienne Pallier
295 3 Etienne Pallier
cd src/
296 3 Etienne Pallier
297 3 Etienne Pallier
$ ./manage.py inspectdb > models.py
298 3 Etienne Pallier
299 3 Etienne Pallier
Traceback (most recent call last):
300 3 Etienne Pallier
  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>
301 3 Etienne Pallier
    import MySQLdb as Database
302 3 Etienne Pallier
  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>
303 3 Etienne Pallier
    import _mysql
304 3 Etienne Pallier
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
305 3 Etienne Pallier
  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
306 3 Etienne Pallier
  Reason: image not found
307 3 Etienne Pallier
308 3 Etienne Pallier
=> BOUH !!!
309 3 Etienne Pallier
310 3 Etienne Pallier
LA SOLUTION EST ICI : http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib
311 3 Etienne Pallier
312 3 Etienne Pallier
(
313 3 Etienne Pallier
Apparemment, ceci aurait dû suffire:
314 3 Etienne Pallier
mkdir -p /usr/local/lib   
315 3 Etienne Pallier
ln -s /usr/local/mysql/lib/libmysql* /usr/local/lib
316 3 Etienne Pallier
)
317 3 Etienne Pallier
318 3 Etienne Pallier
319 3 Etienne Pallier
Mais j’ai fait ceci:
320 3 Etienne Pallier
321 3 Etienne Pallier
$ 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
322 3 Etienne Pallier
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
323 1 Etienne Pallier
	libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
324 10 Etienne Pallier
...
325 3 Etienne Pallier
326 3 Etienne Pallier
$ locate libmysqlclient.18.dylib
327 3 Etienne Pallier
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
328 1 Etienne Pallier
/Library/SystemMigration/History/Migration-68137DFB-CB6A-4FBB-81E2-11BDB5D01E48/QuarantineRoot/usr/lib/libmysqlclient.18.dylib
329 1 Etienne Pallier
330 1 Etienne Pallier
$ 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
331 1 Etienne Pallier
332 10 Etienne Pallier
$ 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
333 10 Etienne Pallier
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
334 10 Etienne Pallier
	/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
335 10 Etienne Pallier
...
336 3 Etienne Pallier
337 1 Etienne Pallier
$ ./manage.py inspectdb > models.py
338 1 Etienne Pallier
339 3 Etienne Pallier
=> YES !!!
340 3 Etienne Pallier
341 3 Etienne Pallier
342 3 Etienne Pallier
343 7 Etienne Pallier
---
344 3 Etienne Pallier
345 7 Etienne Pallier
h3. Create a django application pyrosapp
346 7 Etienne Pallier
347 3 Etienne Pallier
$ ./manage.py startapp pyrosapp
348 3 Etienne Pallier
349 3 Etienne Pallier
$ tree src
350 3 Etienne Pallier
src
351 3 Etienne Pallier
├── db.sqlite3
352 3 Etienne Pallier
├── manage.py
353 3 Etienne Pallier
├── pyros
354 3 Etienne Pallier
│   ├── __init__.py
355 3 Etienne Pallier
│   ├── __pycache__
356 3 Etienne Pallier
│   │   ├── __init__.cpython-35.pyc
357 3 Etienne Pallier
│   │   ├── settings.cpython-35.pyc
358 3 Etienne Pallier
│   │   ├── urls.cpython-35.pyc
359 3 Etienne Pallier
│   │   └── wsgi.cpython-35.pyc
360 3 Etienne Pallier
│   ├── settings.py
361 3 Etienne Pallier
│   ├── urls.py
362 3 Etienne Pallier
│   └── wsgi.py
363 3 Etienne Pallier
└── pyrosapp
364 3 Etienne Pallier
    ├── __init__.py
365 1 Etienne Pallier
    ├── admin.py
366 3 Etienne Pallier
    ├── apps.py
367 1 Etienne Pallier
    ├── migrations
368 1 Etienne Pallier
    │   └── __init__.py
369 3 Etienne Pallier
    ├── models.py
370 3 Etienne Pallier
    ├── tests.py
371 3 Etienne Pallier
    └── views.py
372 1 Etienne Pallier
373 1 Etienne Pallier
374 7 Etienne Pallier
---
375 1 Etienne Pallier
376 7 Etienne Pallier
h3. Replace the default pyrosapp models.py with the inspectdb generated one
377 7 Etienne Pallier
378 3 Etienne Pallier
$ mv models.py pyrosapp/
379 3 Etienne Pallier
380 3 Etienne Pallier
381 3 Etienne Pallier
382 3 Etienne Pallier
383 7 Etienne Pallier
384 1 Etienne Pallier
---
385 9 Etienne Pallier
386 7 Etienne Pallier
*TODO*
387 7 Etienne Pallier
388 7 Etienne Pallier
h3. Fix and improve the inspectdb generated file models.py
389 3 Etienne Pallier
390 3 Etienne Pallier
$ cd pyrosapp/
391 3 Etienne Pallier
392 8 Etienne Pallier
$ vi models.py