-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-doc.html
More file actions
302 lines (252 loc) · 10.2 KB
/
python-doc.html
File metadata and controls
302 lines (252 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8"/>
<title>cpoli</title>
<title>Python installation</title>
<link rel="stylesheet" href="main.css" >
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Droid+Serif">
<link rel="shortcut icon" href="images/cp.ico">
</head>
<body id="body">
<id id="black-strip">
</id>
<div id="top_menu">
<ul>
<li><a href="index.html"><div class="home">Home</div></a></li>
<li><a href="publi.html"><div class="publi">lications</div></a></li>
<li><a href="thesis.html"> <div class="thesis">sis</div></a></li>
<li><a href="vitae.html"> <div class="vitae">ef vitae</div></a></li>
<li><a href="prog.html"><div class="prog">gramming</div></a></li>
</ul>
</div>
<header id=top_header>
<h1> Charles Poli, PhD </h1>
<h2>Head of Artificial Intelligence, </br>
Cambridge Quantum Computing Limited, London.</h2>
</header>
<div id="big_wrapper">
<img src="images/python.jpeg" height="150px" style="margin-left:280px;">
<article>
<header><h1> <a name="doc"></a> <b> <div class="python">hon installation: a super short documentation </b></h1></header>
</br>
<h1>MacOS</h1></br>
The Python installation is done using Xcode and MacPorts.
</br></br></br>
<h2>Get Xcode and Xcode command line tools</h2></br>
In a termminal,
<div class="shell-wrap">
<ul class="shell-body">
<li>xcode-select --install </li>
</ul>
</div>
and follow the instructions.
</br></br>
<h2>Get MacPorts</h2></br>
Go to <a href="http://www.macports.org/install.php">http://www.macports.org/install.php</a> and follow the instructions. </br>
To upgrade, from time to time, the MacPorts:
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port selfupdate</li>
<li>port upgrade outdated</li>
</ul>
</div>
<h2>Get Python</h2></br>
The python version that will be installed is the 3.4. </br>
If you want to install a version XX, just replace in the commands 34 by XX.</br>
In a terminal:
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port install python35</li>
<li>sudo port install py35-setuptools py35-nose</li>
<li># scientific librairies</li>
<li>sudo port install py35-numpy py35-scipy py35-matplotlib</li>
<li># notebook</li>
<li>sudo port install py35-tornado py35-zmq # to use notebook parallel)</li>
<li>sudo port install py35-ipython +notebook +parallel py35-jupyter</li>
<li># machine learning librairies</li>
<li>sudo port install py35-pandas py35-scikit-learn py35-seaborn</li>
</ul>
</div>
To use the command <i>python</i>
<div class="shell-wrap">
<ul class="shell-body">
sudo port select --set python python35
</ul>
</div>
And it's done!
</br></br></br>
<h2>Check Python</h2></br>
In a terminal, launch python:
<div class="shell-wrap">
<ul class="shell-body">
<li>python</li>
</ul>
</div>
and copy paste the following Python commands. </br>
To rapidly check the scientific modules:
<div class="shell-wrap">
<ul class="shell-body">
<li>import numpy as np</li>
<li>import scipy.sparse as sparse</li>
<li>import matplotlib.pyplot as plt</li>
<li>d0 = 9*np.ones(10)</li>
<li>d1 = np.arange(9)</li>
<li>m = sparse.diags([d1, d0, d1], [-1, 0, 1])</li>
<li>print(m.toarray())</li>
<li>a_min, a_max = -1.5, 1.5</li>
<li>a = np.linspace(a_min, a_max, 100)</li>
<li>x, y = np.meshgrid(a, a)</li>
<li>z = np.exp(-x*x-y*y)</li>
<li>fig, ax = plt.subplots()</li>
<li>ax.imshow(z, extent=[a_min, a_max, a_min, a_max])</li>
<li>plt.show()</li>
</ul>
</div>
To rapidly check the machine learning modules:
<div class="shell-wrap">
<ul class="shell-body">
<li>import pandas as pd</li>
<li>import matplotlib.pyplot as plt</li>
<li>import seaborn as sns</li>
<li>sns.set_style('whitegrid')</li>
<li>from pandas.io.data import DataReader</li>
<li>from datetime import datetime</li>
</br>
<li>stocks = ['AAPL', 'NFLX', 'FB']</li>
<li>end = datetime.now()</li>
<li>start = datetime(end.year-1, end.month, end.day)</li>
<li>closing_df = DataReader(stocks, 'yahoo', start, end)['Adj Close']</li>
<li>closing_df.plot(legend=True, figsize=(10, 4), lw=3)</li>
<li>return_df = closing_df.pct_change()</li>
<li>sns.pairplot(return_df .dropna(), size=3)</li>
<li>plt.draw()</li>
<li>plt.show()</li>
</ul>
</div>
<h2>Other tools</h2></br>
<h3>Git</h3>
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port install git</li>
<li>git config --global user.name "Alex Dumas"</li>
<li>git config --global user.email alex@dumas.fr</li>
</ul>
</div>
One can then install packages from GitHub:
<div class="shell-wrap">
<ul class="shell-body">
<li>git clone https://github.com/jakevdp/JSAnimation </li>
<li># I picked up a package to create animations in python notebooks </li>
<li>cd JSAnimation</li>
<li>python setup.py build</li>
<li>sudo python setup.py install</li>
</ul>
</div>
<h3>Text Editors / IDEs</h3></br>
Xcode (for mac users)
<br>
Note that Xcode is aleady installed.
<div class="shell-wrap">
<ul class="shell-body">
<li>touch test.py # create an empty file</li>
<li>open test.py # open the file with Xcode</li>
</ul>
</div>
Sublime
<br>
Download <a href="http://www.sublimetext.com/3">http://www.sublimetext.com/3</a> and install Sublime.
<br>
To call Sublime from the Terminal:
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin</li>
</ul>
</div>
Then, to open a file using Sublime:
<div class="shell-wrap">
<ul class="shell-body">
<li>touch test.py</li>
<li>subl test.py</li>
</ul>
</div>
Emacs
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port install emacs</li>
<li>sudo port install emacs-app</li>
<li>emacs test.py # open the file in the terminal</li>
</ul>
</div>
To use your alt and meta keys as usual <br>
Go to “Emacs” → “Preferences” → “Environment” → “Ns : GNUstep/Mac OS X specific features”<br>
and change the following: <br>
“Ns Command Modifier” → “meta“ <br>
“Ns Alternate Modifier” → “No modifier“ <br>
<br>
To change the background and mouse color <br>
open your “~/.emacs“ <br>
paste the following code snippet: <br>
(setq default-frame-alist <br>
(append default-frame-alist <br>
'((foreground-color . "LawnGreen") <br>
(background-color . "Black") <br>
(cursor-color . "LawnGreen")))) <br>
<br>
IPython notebook
<div class="shell-wrap">
<ul class="shell-body">
<li>ipython notebook</li>
</ul>
</div>
<h1>Ubuntu</h1></br>
Just go to the Mac section and replace
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port</li>
</ul>
</div>
by
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo get-apt</li>
</ul>
</div>
<h1>Debian</h1></br>
Just go to the Mac section and replace
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port</li>
</ul>
</div>
by
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo yum</li>
</ul>
</div>
<h1>Windows</h1></br>
<!--
<h2>Get PowerShell</h2></br>
Download and install the last version of Windows Management Framework
<a href="https://www.microsoft.com/en-us/download/details.aspx?id=40855">https://www.microsoft.com/en-us/download/details.aspx?id=40855</a>.
https://www.microsoft.com/en-us/download/details.aspx?id=40855
-->
<h2>Get Python</h2></br>
Download and execute a Python version
<a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a>. </br>
Just go to the Mac section and replace
<div class="shell-wrap">
<ul class="shell-body">
<li>sudo port</li>
</ul>
</div>
by
<div class="shell-wrap">
<ul class="shell-body">
<li>pip</li>
</ul>
</div>
You can also download the unofficial Windows binaries from
<a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">http://www.lfd.uci.edu/~gohlke/pythonlibs</a>
</article>