-
Notifications
You must be signed in to change notification settings - Fork 29
/
getstarted.html
184 lines (165 loc) · 12.5 KB
/
getstarted.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CME 193 - Scientific Python</title>
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/font-awesome.min.css">
<link rel="stylesheet" href="./css/highlight.tomorrow-night.css">
<link rel="stylesheet" href="./css/main.css">
</head>
<body>
<header class="navbar navbar-default navbar-fixed-top">
<a class="navbar-brand" href="./">
CME 193 - Scientific Python
<small class="hidden-xs hidden-sm">
Stanford University
</small>
</a>
</header>
<main class="container-fluid">
<div class="row">
<nav id="sidebar" class="col-sm-3 col-lg-2" role="navigation">
<p class="text-muted">
Course Information
</p>
<ul class="nav nav-pills nav-stacked">
<li class="">
<a href="./index.html">
Course Description
</a>
</li>
<li class="">
<a href="./syllabus.html">
Syllabus
</a>
</li>
<li class="">
<a href="./lectures.html">
Lectures
</a>
</li>
<li class="">
<a href="./homework.html">
Homework
</a>
</li>
</ul>
<p class="text-muted">
Other Links
</p>
<ul class="nav nav-pills nav-stacked">
<li class="">
<a href="./getstarted.html">
Getting Started
</a>
</li>
<li class="">
<a href="./jupyter.html">
Jupyter
</a>
</li>
</ul>
</nav>
<section class="col-sm-offset-3 col-lg-offset-2 col-sm-9 col-lg-10">
<h1 id="getting-started">Getting started</h1>
<p>Getting started with Python can be a little confusing, hopefully this page helps to get you going.</p>
<p>In general, I am not going to tell you to do things one way. This is because there are a variety of operating systems, and some of you may already have development environments set up in a particular way. The best ways to troubleshoot installation and environment issues are:</p>
<ol>
<li>Consult the internet</li>
<li>Consult a friend/neighbor with the same operating system</li>
</ol>
<p>Personally, I run Fedora (linux) on my machine. Unless you are as well, you may find that I fall back on steps 1 and 2 above if you ask me for help.</p>
<p>For anyone who is new to Python or maintaining any sort of development environment on a computer, I recommend Anaconda python.</p>
<h2 id="installing-python">Installing Python</h2>
<p>In this class, we will be using Python 3.6. If you want to use a different version, you can try, but the material provided in class may not run with your different version. In particular, if you are using Python 2, you are particularly likely to see things not work. We recommend having some Python 3 interpreter available.</p>
<p>In the terminal, you can check which python version you are currently using with</p>
<pre><code class="language-bash">python -V # -V is the same as --version</code></pre>
<p>You may have a python 2 interpreter as well as a python 3 interpreter. Often these can be invoked as</p>
<pre><code class="language-bash">python2 -V # python 2 version
python3 -V # python 3 version</code></pre>
<p>Following are a variety of methods you can use to install Python. As far as this course is concerned, you can use whatever you want (if you already have system python or anaconda working for you, don't change just for the course).</p>
<p>If you are new to Python, I recommend using Anaconda, regardless of operating system. You can always change your mind later. <a href="https://conda.io/docs/user-guide/tasks/manage-environments.html">Conda environments</a> are enough of a reason to at least give it a try.</p>
<h3 id="anaconda">Anaconda</h3>
<p>One convenient method to set up your Python environment is using a free, pre-packaged distribution, such as <a href="https://www.anaconda.com/download/">Anaconda</a>.</p>
<p>This has the advantage that many relevant packages come pre-installed, possibly saving you some headaches later on. It also includes <em>pip</em>, the Python package manager.</p>
<p>Note that while Anaconda also comes with the Anaconda launcher and a bunch of other tools, you should not be using any of these for this course.
We only use Anaconda for the convenience of installation of Python and the main packages, not the other stuff that comes with it as well.</p>
<p>If you are a Windows user, Anaconda is recommended, as Windows is notorious for not playing nice with Python.</p>
<h3 id="system-package-manager-linux">System Package Manager (Linux)</h3>
<p>If you're running Linux, you can just use your package manager (<em>apt-get</em>, <em>dnf</em>, etc.) to install Python. You can also often use your package manager to install Python packages instead of <em>pip</em>, but you may run into issues doing this.</p>
<h3 id="homebrew-mac-only">Homebrew (Mac only)</h3>
<p>If you want a bit more control over your Python distribution, then using Homebrew to install Python is useful.</p>
<p>It also installs the package manager <em>pip</em> for you, which is very useful.</p>
<p>However, it does not come with additional modules, such as <em>numpy</em> or <em>scipy</em>,
though they can be installed easily using <em>pip</em>.</p>
<p>A short tutorial can be found <a href="http://docs.python-guide.org/en/latest/starting/install/osx/">here</a>.</p>
<h3 id="note-to-windows-users">Note to Windows Users</h3>
<p>If you are a Windows user and are serious about taking this <em>and</em> other computer classes, I recommend using the <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Windows Subsystem for Linux</a>. In general, much scientific computing is done on clusters running some form of Linux. The sooner you start using Linux, the better.</p>
<p>If you really want to take the plunge, you can also partition your hard drive and add a linux distribution as a second operating system.</p>
<p>If the install guides for Anaconda fail, and some Googling leads to nothing of utility, I highly suggest running with a cloud-based option.</p>
<h2 id="editor">Editor</h2>
<p>To write code, you need an editor.
While there are many options, old and new, <a href="https://atom.io/">Atom</a> is (generally) what I use.</p>
<p>A script is a simple file with text, such as</p>
<pre><code class="language-python">a = 'Hello,'
b = 'world!'
print(a + ' ' + b)</code></pre>
<p>which you can save to your <em>filesystem</em> using the editor.</p>
<h2 id="running-code">Running code</h2>
<p>Now that you know how to write Python scripts, it's time to learn how to run them using Python.</p>
<h3 id="linux">Linux</h3>
<p>Open a terminal.</p>
<p>To open the interpreter, enter <code>python</code></p>
<p>To run a script enter <code>python <script>.py</code> where <code><script>.py</code> is the path to the script.</p>
<h3 id="mac">Mac</h3>
<p>Open the <em>terminal</em>, for example by searching for terminal using the spotlight search function.</p>
<p>To open the interpreter, simply enter <em>python</em> (this is the interactive mode).</p>
<p>To run a script, navigate to the folder that contains your script. Then simply run <code>python script.py</code>, given that <code>script.py</code> is the name of your script.</p>
<p>Online, you can find some good resources that introduce the terminal, such as</p>
<ul>
<li><a href="http://mac.appstorm.net/how-to/utilities-how-to/how-to-use-terminal-the-basics/">How to Use Terminal: The Basics</a></li>
<li><a href="http://computers.tutsplus.com/tutorials/navigating-the-terminal-a-gentle-introduction--mac-3855">Navigating the Terminal: A Gentle Introduction</a></li>
<li><a href="http://www.maclife.com/article/feature/25_terminal_tips_every_mac_user_should_know">25 Terminal Tips Every Mac User Should Know</a></li>
<li><a href="http://jolts.stanford.edu/48/getting_started_with_linux">Getting started with Linux, Section 3 and beyond</a> (Note that Linux and Mac have the same terminal)</li>
<li><a href="https://practicalunix.org/">Stanford course CS 1U 'Practical Unix'</a></li>
</ul>
<h3 id="windows">Windows</h3>
<p>Open the <em>command prompt</em> by searching for <code>cm</code>+ in the Start menu.
This is the Windows version of the terminal.</p>
<p>To open the interpreter, similar to the Mac terminal, we simply run +python+.</p>
<p>To run a script, navigate to the folder that contains your script, and then run <code>python script.py</code>, given that <code>script.py</code> is the file name.</p>
<p>For Windows, there are some good resources about the command prompt</p>
<ul>
<li><a href="http://dosprompt.info/">Command Prompt Basics - A Getting Started Guide</a></li>
<li><a href="http://www.cs.princeton.edu/courses/archive/spr05/cos126/cmd-prompt.html">Windows Command Prompt in 15 Minutes</a></li>
</ul>
<p>If you are using Windows and you're having trouble setting up Python, I recommend using Python <em>in the cloud</em>, as I'll discuss later.</p>
<h2 id="pip">Pip</h2>
<p>To install new modules, make sure you have <code>pip</code> installed.
It comes with both Anaconda and Homebrew, so if you have used either of them, you are good.
Otherwise, it is also rather straightforward to install <code>pip</code>: See the <a href="http://pip.readthedocs.org/en/latest/installing.html">documentation</a>.</p>
<p>Then, open the terminal / command prompt, and run <code>pip install module</code>, where <code>module</code> is the name of the module.</p>
<p><strong>Note that you cannot run this from inside the Python interpreter.</strong></p>
<h2 id="python-in-the-cloud">Python in the cloud</h2>
<p>When you have trouble getting Python up and running, or if you have Windows and would like to use a Unix environment, then there is an alternative: using your browser.</p>
<p>One option is <a href="https://aws.amazon.com/">AWS</a>.</p>
<p>If anyone has other suggestions, I am open to them.</p>
<h2 id="farmshare">Farmshare</h2>
<p>Another option available to everyone is <a href="https://srcc.stanford.edu/farmshare2">farmshare</a>. You simply need to <code>ssh</code> in, and you will have a full working installation of python. This requires some Linux skills, so follow <a href="https://web.stanford.edu/group/farmshare/cgi-bin/wiki/index.php/User_Guide">this guide</a> to getting started.</p>
</section>
</div>
</main>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//yandex.st/highlightjs/7.5/highlight.min.js"></script>
<script>
$(function() {
$("section>h1").wrap('<div class="page-header" />');
// Syntax highlighting
hljs.initHighlightingOnLoad();
});
</script>
</body>
</html>