-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhowto.html
More file actions
128 lines (101 loc) · 7.79 KB
/
howto.html
File metadata and controls
128 lines (101 loc) · 7.79 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://www.owencampbell.me.uk/images/favicon/favicon.ico" rel="icon">
<title>SQL for Python Programmers</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<link href="https://www.owencampbell.me.uk/theme/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="/sql_python_tutorial/static/styles.css">
</head>
<body>
<div class="fixed-top">
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="#">SQL for Python Programmers</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarContent">
<div class="navbar-nav">
<a class="nav-item nav-link" href="/sql_python_tutorial/"><i class="fa fa-home fa-fw" aria-hidden="true" title="home"></i> Home</a>
<a class="nav-item nav-link mr-auto" href="/sql_python_tutorial/chapters/"><i class="fa fa-book fa-fw" aria-hidden="true" title="contents"></i> Contents</a>
<a class="nav-item nav-link" href="/sql_python_tutorial/pages/intro.html"><i class="fa fa-info-circle fa-fw" aria-hidden="true" title="introduction"></i> Introduction</a>
<a class="nav-item nav-link" href="/sql_python_tutorial/pages/howto.html"><i class="fa fa-gears fa-fw" aria-hidden="true" title="how to"></i> How To</span></a>
<a class="nav-item nav-link" href="/sql_python_tutorial/pages/primer.html"><i class="fa fa-database fa-fw" aria-hidden="true" title="primer"></i> Primer</a>
</div>
<div class="navbar-nav ml-auto">
<a class="btn btn-link btn-lg" href="https://www.linkedin.com/in/owencampbell" title="linkedin"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
<a class="btn btn-link btn-lg" href="http://github.com/meatballs" title="github"><i class="fa fa-github" aria-hidden="true"></i></a>
</div>
</div>
</nav>
</div>
<main role="main" class="container">
<h1><i class="fa fa-cogs" aria-hidden="true"></i> How To Use This Tutorial</h1>
<p>If you prefer to read the tutorial in your web browser without executing any of the code, then head over to the <a href="/sql_python_tutorial/chapters/">contents</a> page and follow the links for each of the chapters.</p>
<p>However, the content of the tutorial is written using interactive <a href="https://jupyter.org/">Jupyter Notebooks</a>. This means that all of the code can be run from within the tutorial itself. You can edit the code, add new code of your own and run it all!</p>
<p><i>If you have never used a Jupyter notebook before, you may want to have a look at the <a href="https://jupyter-notebook.readthedocs.io/en/stable/notebook.html#notebook-user-interface">documentation</a>. Alternatively, Corey Shafer produced a very good <a href="https://www.youtube.com/watch?v=HW29067qVWk">video tutorial</a> where he installs a Jupyter server on his computer (option 2 below) and shows you how to use it. (If you choose option 1 below, you can ignore where he installs and starts his server).</i></p>
<p>To run the notebooks, you need a server. There are two options:</p>
<h2 id="howto-binder">1. Use an Online Service</h2>
<p>This is the simplest option. There is nothing to install on your computer and everything is done within your web browser.</p>
<p>If you choose this option, be aware that:</p>
<ul>
<li>The server will take a few moments to start, especially at times when the service is busy.</li>
<li>Nothing is saved between sessions. If you close your web browser, any changes you have made to the code or the sample database will be lost.</li>
<li>The code typically takes longer to execute than it would on a local computer. In particular, it is best not to run the first example in <a href="/sql_python_tutorial/chapters/12/">Chapter 12 - Bulk Loading</a>.
</ul>
<p><a class="btn btn-primary btn-lg" href="https://mybinder.org/v2/gh/meatballs/sql_python_notebooks/master" role="button">Launch Notebook Server <i class="fa fa-play fa-fw" aria-hidden="true"></i></a></p>
<h2 id="howto-local">2. Use Your Own Computer</h2>
<p>Using your own computer allows you to work offline and to keep any changes you make to the code or the sample database. It does, however, require you to install some software before you can start:</p>
<h3>2.1. Recommended Method - Anaconda</h3>
<p>The <a href="https://www.anaconda.com/download/">Anaconda</a> distribution of Python includes most of the necessary tools for this tutorial and so is the simplest option for running the code on your own computer.</p>
<p>Create a virtual environment:</p>
<div class="code-block">
<pre><code>
conda create -n sql-python -python=3.6
</code></pre>
</div>
<p>Install sqlalchemy:</p>
<div class="code-block">
<pre><code>
conda install -c anaconda sqlalchemy
</code></pre>
</div>
<h3>2.2 Other Python Distributions</h3>
<p>For other Python distributions you can install the necessary libraries using pip. It is strongly recommended that you create a virtual environment before doing so.</p>
<div class="code-block">
<pre><code>
pip install jupyter pandas sqlalchemy
</code></pre>
</div>
<h3>2.3. Running the Notebooks</h3>
<p>Each chapter listed on the <a href="/sql_python_tutorial/chapters/">Contents</a> page has a link which you can use to download the notebook file. Place these files in a directory of your choice and then, in your terminal, change to that directory and start the Jupyter server:</p>
<div class="code-block">
<pre><code>
jupyter notebook
</code></pre>
</div>
<p>After a few moments, your browser will open a page which lists all the notebooks you downloaded.</p>
<h3 id="flight-data-file">2.4 Optional Bulk Data File</h3>
<p><a href="/sql_python_tutorial/chapters/12/">Chapter 12 - Bulk Loading</a> uses a 70 MB file with over 200 000 records. If you intend to work through that chapter, you will need to <a href="http://www.owencampbell.me.uk/sql_python_tutorial/notebooks/flight-data.csv" download>download the file</a> to the same directory as the notebooks</p>
<h3 id="howto-db-browser">2.5 Optional Database Browser</h3>
<p>Although the tutorial focuses on using Python to control a database, it can sometimes be useful to use a command line or graphical tool. Some of the chapters include examples of using the open source <a href="http://sqlitebrowser.org/">DB Browser for SQLite</a> in addition to the Python examples.
</main>
<footer class="footer d-none d-md-block">
<div class="container">
<span class="text-muted">
<p class="small">
This tutorial was inspired by a talk given by <a href="https://twitter.com/waveform80">Dave Jones</a> at <a href="https://twitter.com/pythonnw">Python North West</a>.
The flights database, and much of the SQL code, is taken, with grateful thanks,
from the <a href="https://waveform.org.uk/presentations/sql">slides</a> and
<a href="https://github.com/waveform80/presentations">source code</a> for that talk.
<br/>
Many thanks also to <a href="https://vknight.org/">Dr. Vincent Knight</a> of <a href="http://www.cardiff.ac.uk">Cardiff University</a> for the use of his
<a href="https://vknight.org/gt/">Game Theory Course Notes</a> and their <a href="https://github.com/drvinceknight/gt">source code</a>.
</p>
</span>
</div>
</footer>
</body>
</html>