Wiki

Version 34 (Etienne Pallier, 03/18/2016 10:45 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 28 Etienne Pallier
$ cd pyros/
216 12 Etienne Pallier
217 12 Etienne Pallier
218 12 Etienne Pallier
 
219 29 Etienne Pallier
Example of a good organization :
220 1 Etienne Pallier
221 29 Etienne Pallier
1 project = N applis
222 29 Etienne Pallier
(but 1 appli can be part of many projects)
223 30 Etienne Pallier
(then 1 appli = N models)
224 12 Etienne Pallier
225 31 Etienne Pallier
<pre>
226 34 Etienne Pallier
227 29 Etienne Pallier
MYPROJECT/
228 34 Etienne Pallier
229 1 Etienne Pallier
	src/
230 1 Etienne Pallier
		myproject/
231 34 Etienne Pallier
		appli1/
232 34 Etienne Pallier
		appli2/
233 12 Etienne Pallier
234 34 Etienne Pallier
		appliN/
235 34 Etienne Pallier
236 12 Etienne Pallier
	public/
237 34 Etienne Pallier
		static/
238 34 Etienne Pallier
239 12 Etienne Pallier
	private/
240 1 Etienne Pallier
		requirements.txt
241 31 Etienne Pallier
</pre>
242 12 Etienne Pallier
243 12 Etienne Pallier
244 12 Etienne Pallier
---
245 12 Etienne Pallier
246 12 Etienne Pallier
h3. Set needed folders (inside pyros/)
247 12 Etienne Pallier
248 12 Etienne Pallier
$ mkdir private public
249 12 Etienne Pallier
$ mkdir public/static
250 1 Etienne Pallier
251 3 Etienne Pallier
252 7 Etienne Pallier
---
253 3 Etienne Pallier
254 7 Etienne Pallier
h3. Create django project pyros
255 7 Etienne Pallier
256 3 Etienne Pallier
$ django-admin startproject pyros
257 3 Etienne Pallier
258 3 Etienne Pallier
$ tree pyros/
259 3 Etienne Pallier
pyros/
260 3 Etienne Pallier
├── manage.py
261 3 Etienne Pallier
└── pyros
262 3 Etienne Pallier
    ├── __init__.py
263 3 Etienne Pallier
    ├── settings.py
264 3 Etienne Pallier
    ├── urls.py
265 3 Etienne Pallier
    └── wsgi.py
266 3 Etienne Pallier
267 3 Etienne Pallier
268 3 Etienne Pallier
$ mv pyros src
269 3 Etienne Pallier
270 3 Etienne Pallier
$ cd src/
271 3 Etienne Pallier
272 1 Etienne Pallier
$ ./manage.py runserver
273 3 Etienne Pallier
(ou gunicorn pyros.wsgi)
274 1 Etienne Pallier
==> http://localhost:8000
275 1 Etienne Pallier
276 3 Etienne Pallier
277 3 Etienne Pallier
278 7 Etienne Pallier
---
279 3 Etienne Pallier
280 7 Etienne Pallier
h3. Set Database mysql
281 7 Etienne Pallier
282 3 Etienne Pallier
Edit src/pyros/settings.py
283 3 Etienne Pallier
284 3 Etienne Pallier
DATABASES = {
285 3 Etienne Pallier
    'default': {
286 3 Etienne Pallier
        'ENGINE': 'django.db.backends.mysql',
287 1 Etienne Pallier
        'NAME': 'pyros',
288 3 Etienne Pallier
        'USER': 'root',
289 1 Etienne Pallier
        'PASSWORD': ''
290 1 Etienne Pallier
    }
291 3 Etienne Pallier
}
292 3 Etienne Pallier
293 3 Etienne Pallier
294 7 Etienne Pallier
---
295 3 Etienne Pallier
296 7 Etienne Pallier
h3. Import database into django
297 7 Etienne Pallier
298 3 Etienne Pallier
cd src/
299 3 Etienne Pallier
300 3 Etienne Pallier
$ ./manage.py inspectdb > models.py
301 3 Etienne Pallier
302 3 Etienne Pallier
Traceback (most recent call last):
303 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>
304 3 Etienne Pallier
    import MySQLdb as Database
305 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>
306 3 Etienne Pallier
    import _mysql
307 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
308 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
309 3 Etienne Pallier
  Reason: image not found
310 3 Etienne Pallier
311 3 Etienne Pallier
=> BOUH !!!
312 3 Etienne Pallier
313 3 Etienne Pallier
LA SOLUTION EST ICI : http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib
314 3 Etienne Pallier
315 3 Etienne Pallier
(
316 3 Etienne Pallier
Apparemment, ceci aurait dû suffire:
317 3 Etienne Pallier
mkdir -p /usr/local/lib   
318 3 Etienne Pallier
ln -s /usr/local/mysql/lib/libmysql* /usr/local/lib
319 3 Etienne Pallier
)
320 3 Etienne Pallier
321 3 Etienne Pallier
322 3 Etienne Pallier
Mais j’ai fait ceci:
323 3 Etienne Pallier
324 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
325 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:
326 1 Etienne Pallier
	libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
327 10 Etienne Pallier
...
328 3 Etienne Pallier
329 3 Etienne Pallier
$ locate libmysqlclient.18.dylib
330 3 Etienne Pallier
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
331 1 Etienne Pallier
/Library/SystemMigration/History/Migration-68137DFB-CB6A-4FBB-81E2-11BDB5D01E48/QuarantineRoot/usr/lib/libmysqlclient.18.dylib
332 1 Etienne Pallier
333 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
334 1 Etienne Pallier
335 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
336 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:
337 10 Etienne Pallier
	/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
338 10 Etienne Pallier
...
339 3 Etienne Pallier
340 1 Etienne Pallier
$ ./manage.py inspectdb > models.py
341 1 Etienne Pallier
342 3 Etienne Pallier
=> YES !!!
343 3 Etienne Pallier
344 3 Etienne Pallier
345 3 Etienne Pallier
346 7 Etienne Pallier
---
347 3 Etienne Pallier
348 7 Etienne Pallier
h3. Create a django application pyrosapp
349 7 Etienne Pallier
350 3 Etienne Pallier
$ ./manage.py startapp pyrosapp
351 3 Etienne Pallier
352 3 Etienne Pallier
$ tree src
353 3 Etienne Pallier
src
354 3 Etienne Pallier
├── db.sqlite3
355 3 Etienne Pallier
├── manage.py
356 3 Etienne Pallier
├── pyros
357 3 Etienne Pallier
│   ├── __init__.py
358 3 Etienne Pallier
│   ├── __pycache__
359 3 Etienne Pallier
│   │   ├── __init__.cpython-35.pyc
360 3 Etienne Pallier
│   │   ├── settings.cpython-35.pyc
361 3 Etienne Pallier
│   │   ├── urls.cpython-35.pyc
362 3 Etienne Pallier
│   │   └── wsgi.cpython-35.pyc
363 3 Etienne Pallier
│   ├── settings.py
364 3 Etienne Pallier
│   ├── urls.py
365 3 Etienne Pallier
│   └── wsgi.py
366 3 Etienne Pallier
└── pyrosapp
367 3 Etienne Pallier
    ├── __init__.py
368 1 Etienne Pallier
    ├── admin.py
369 3 Etienne Pallier
    ├── apps.py
370 1 Etienne Pallier
    ├── migrations
371 1 Etienne Pallier
    │   └── __init__.py
372 3 Etienne Pallier
    ├── models.py
373 3 Etienne Pallier
    ├── tests.py
374 3 Etienne Pallier
    └── views.py
375 1 Etienne Pallier
376 1 Etienne Pallier
377 7 Etienne Pallier
---
378 1 Etienne Pallier
379 7 Etienne Pallier
h3. Replace the default pyrosapp models.py with the inspectdb generated one
380 7 Etienne Pallier
381 3 Etienne Pallier
$ mv models.py pyrosapp/
382 3 Etienne Pallier
383 3 Etienne Pallier
384 3 Etienne Pallier
385 3 Etienne Pallier
386 7 Etienne Pallier
387 1 Etienne Pallier
---
388 9 Etienne Pallier
389 7 Etienne Pallier
*TODO*
390 7 Etienne Pallier
391 7 Etienne Pallier
h3. Fix and improve the inspectdb generated file models.py
392 3 Etienne Pallier
393 3 Etienne Pallier
$ cd pyrosapp/
394 3 Etienne Pallier
395 8 Etienne Pallier
$ vi models.py