Wiki

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