Skip to content

Commit 039de3f

Browse files
authored
Chapter End
1 parent 820638b commit 039de3f

File tree

13 files changed

+321
-0
lines changed

13 files changed

+321
-0
lines changed

1. Getting Started/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Chapter 1
2+
===
3+
4+
Setting Up
5+
---
6+
7+
Python runs on all modern operating systems, but the setup process is slightly different on each operating system:
8+
9+
- [Linux](linux_setup.md)
10+
- [OS X](osx_setup.md)
11+
- [Windows](windows_setup.md)
76.1 KB
Loading
132 KB
Loading
99.3 KB
Loading

1. Getting Started/hello_world.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello Python world!")

1. Getting Started/linux_setup.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
Setup Instructions: Linux
2+
===
3+
4+
- [Checking your current version of Python](#current_version)
5+
- [Installing Python 3.5](#python3.5)
6+
- [Installing Geany](#installing_geany)
7+
- [Configuring Geany](#configuring_geany)
8+
9+
<a name='current_version'></a>Checking your current version of Python
10+
---
11+
12+
Python is probably already installed on your system. Find out which version is your default by issuing the command `python --version`:
13+
14+
$ python --version
15+
Python 2.7.6
16+
17+
If you see something like this, Python 2.7 is your default version. You should also see if you have Python 3 installed:
18+
19+
$ python3 --version
20+
Python 3.4.0
21+
22+
If you have Python 3.4 or later, it's fine to start out by using the installed version. If you have Python 3.3 or earlier, it's probably worth installing Python 3.5.
23+
24+
[top](#)
25+
26+
<a name='python3.5'></a>Installing Python 3.5
27+
---
28+
29+
The following instructions should work on Ubuntu, and most Debian-based systems that use the apt package manager.
30+
31+
Add the *deadsnakes* package, and then install Python 3.5:
32+
33+
$ sudo add-apt-repository ppa:fkrull/deadsnakes
34+
$ sudo apt-get update
35+
$ sudo apt-get install python3.5
36+
37+
You can confirm that the installation was successful:
38+
39+
$ python3.5 --version
40+
Python 3.5.0
41+
42+
Now to start a Python terminal session, you'll use the command `python3.5`:
43+
44+
$ python3.5
45+
Python 3.5.0 (default, Sep 17 2015, 00:00:00)
46+
[GCC 4.8.4] on linux
47+
Type "help", "copyright", "credits" or "license" for more information.
48+
>>>
49+
50+
You'll use this command when you configure your text editor, and when you run programs from the terminal.
51+
52+
[top](#)
53+
54+
<a name='installing_geany'></a>Installing Geany
55+
---
56+
57+
On Ubuntu and other systems that use the apt package manager, you can install Geany in one line:
58+
59+
$ sudo apt-get install geany
60+
61+
If this doesn't work, you can see the instructions at [http://geany.org/Download/ThirdPartyPackages/](http://geany.org/Download/ThirdPartyPackages/).
62+
63+
[top](#)
64+
65+
<a name='configuring_geany'></a>
66+
### Configuring Geany
67+
68+
If you use the simple command `python` to start a terminal session on your system, you shouldn't have to configure Geany at all. But if you use a command like `python3` or `python3.5`, you'll have to modify Geany slightly so it uses the correct version of Python to run your programs.
69+
70+
Open an empty file and save it as *hello_world.py*. The file should have one line in it:
71+
72+
print("Hello Python world!")
73+
74+
Go to **Build>Set Build Commands**. You should see the word *Compile*, and a command next to the word *Compile*. Change this to
75+
76+
python3 -m py_compile "%f"
77+
78+
If you use a command like `python3.5`, make sure you use that command instead.
79+
80+
Next to the word *Execute*, enter the following command:
81+
82+
python3 "%f"
83+
84+
Again, if you use a command like `python3.5`, make sure you use that command.
85+
86+
Now you can run programs by selecting **Build>Execute**, clicking the Execute icon with a set of gears on it, or by pressing **F5**.
87+
88+
[top](#)
89+
90+
91+

1. Getting Started/osx_setup.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Setup Instructions: OS X
2+
===
3+
4+
- [Checking your current version of Python](#current_version)
5+
- [Installing Python 3.5](#python3.5)
6+
- [Installing Sublime Text](#installing_st)
7+
- [Configuring Sublime Text](#configuring_st)
8+
9+
<a name='current_version'></a>Checking your current version of Python
10+
---
11+
12+
Python is probably already installed on your system. To check if it's installed, go to **Applications>Utilities** and click on **Terminal**. (You can also press command-spacebar, type *terminal*, and then press Enter.)
13+
14+
Find out which version of Python is installed by issuing the command `python --version`:
15+
16+
$ python --version
17+
Python 2.7.5
18+
19+
If you see something like this, Python 2.7 is your default version. You should also see if you have Python 3 installed:
20+
21+
$ python3 --version
22+
Python 3.4.0
23+
24+
If you have Python 3.4 or later, it's fine to start out by using the installed version. If you have Python 3.3 or earlier, it's probably worth installing Python 3.5.
25+
26+
[top](#)
27+
28+
<a name='python3.5'></a>Installing Python 3.5
29+
---
30+
31+
Install [Homebrew](http://brew.sh/), which makes it easy to install the most recent version of Python. Start out by installing some of Apple's xcode tools:
32+
33+
$ xcode-select --install
34+
35+
The installation may take a while, depending on the speed of your connection. Next, install Homebrew:
36+
37+
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
38+
39+
If you run the command **brew doctor**, you can verify that the installation was successful:
40+
41+
$ brew doctor
42+
Your system is ready to brew.
43+
44+
Now you can install Python packages through Homebrew. To install Python 3, enter the following command:
45+
46+
$ brew install python3
47+
48+
You can verify that Python 3 was installed correctly:
49+
50+
$ python3 --version
51+
Python 3.5.0
52+
53+
You'll use the **python3** command when you configure your text editor, when you start a Python terminal session, and when you run programs from the terminal.
54+
55+
[top](#)
56+
57+
<a name='installing_st'></a>Installing Sublime Text
58+
---
59+
60+
You can download an installer for Sublime Text by clicking on the OS X link at [http://www.sublimetext.com/3](http://www.sublimetext.com/3). Sublime Text has a liberal licensing policy; it's free as long as you want to use it, but the author requests that you purchase a license if you like the program and want to continue using it.
61+
62+
After you've downloaded the installer, open it and then drag the Sublime Text icon into your *Applications* folder.
63+
64+
[top](#)
65+
66+
<a name='configuring_st'></a>
67+
### Configuring Sublime Text for Python 3
68+
69+
If you use the simple command `python` to start a terminal session on your system, you shouldn't have to configure Sublime Text at all. But if you use a command like `python3` or `python3.5`, you'll have to modify Sublime Text slightly so it uses the correct version of Python to run your programs.
70+
71+
Find the path to your Python interpreter:
72+
73+
$ type -a python3
74+
python3 is /usr/local/bin/python3
75+
76+
Open an empty file in Sublime Text and save it as *hello_world.py*. The file should have one line in it:
77+
78+
print("Hello Python world!")
79+
80+
Go to **Tools>Build System>New Build System**, which will open a new configuration file. Delete what you see, and enter the following:
81+
82+
{
83+
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
84+
}
85+
86+
This tells Sublime Text to use your system's **python3** command when running programs. Make sure you use the path you found when running **type -a python3**, not necessarily the path you see here. Save the file as *Python3.sublime-build* in the directory that Sublime Text opens when you choose Save.
87+
88+
Now you can run programs by selecting **Build>Execute**, clicking the Execute icon with a set of gears on it, or by pressing **F5**.
89+
90+
[top](#)
91+
92+
93+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
Setup Instructions: Windows
2+
===
3+
4+
- [Checking your current version of Python](#current_version)
5+
- [Installing Python 3.5](#python3.5)
6+
- [Adding Python to Your Path Variable](#path_variable)
7+
- [Installing Geany](#installing_geany)
8+
- [Configuring Geany](#configuring_geany)
9+
10+
<a name='current_version'></a>Checking your current version of Python
11+
---
12+
13+
Python may already installed on your system. Open a command window by right-clicking on the Desktop while holding the shift key, and then select "Open Command Window Here". You can also search for "command" in the task bar. Find out which version is your default by issuing the command `python --version`:
14+
15+
> python --version
16+
Python 2.7.6
17+
18+
If you see something like this, Python 2.7 is your default version. You should also see if you have Python 3 installed:
19+
20+
> python3 --version
21+
Python 3.4.0
22+
23+
If you have Python 3.4 or later, it's fine to start out by using the installed version. If you have Python 3.3 or earlier, it's probably worth installing Python 3.5.
24+
25+
If you get an error message for both of these commands, Python is not installed on your system, and you should install Python 3.5.
26+
27+
[top](#)
28+
29+
<a name='python3.5'></a>Installing Python 3.5
30+
---
31+
32+
Go to [https://www.python.org/downloads/](https://www.python.org/downloads/) and click the button labeled "Download Python 3.5". Download the installer, and when you run it make sure to check the *Add Python to PATH* option:
33+
34+
![Add Python to PATH box checked](figures/crash_course01-02.png)
35+
36+
Checking this button ensures that you'll be able to use the simple command **python**. If you missed this step, see [Adding Python to Your Path Variable](#path_variable).
37+
38+
You can confirm that the installation was successful:
39+
40+
> python --version
41+
Python 3.5.0
42+
43+
Now to start a Python terminal session, you'll use the command `python`:
44+
45+
> python
46+
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
47+
Type "help", "copyright", "credits" or "license" for more information.
48+
>>>
49+
50+
You'll use this command when you configure your text editor, and when you run programs from the terminal.
51+
52+
[top](#)
53+
54+
<a name='path_variable'></a>Adding Python to Your Path Variable
55+
---
56+
If you checked *Add Python to PATH* when you installed Python and the command **python** works, you can skip this step.
57+
58+
To find the path to Python on your system, open Windows Explorer and look in your C:\ drive. Look for a folder starting with *Python*; you might need to enter *python* in the Windows Explorer search bar to find the right folder. Open the folder, and look for a file with the lowercase name *python*. Right-click this file and choose **Properties**; you'll then see the path to this file under the heading Location.
59+
60+
In a terminal window, use the path to confirm the version you just installed:
61+
62+
> C:\\Python35\python --version
63+
Python 3.5.0
64+
65+
Open your system's **Control Panel**, choose **System and Security**, and then choose **System**. Click **Advanced System Settings*, and in the window that pops up click **Environment Variables**.
66+
67+
In the box labeled *System variables*, look for a variable called `Path`. Click **Edit**. In the box that pops up, click in the box labeled *Variable Value* and use the right arrow key to scroll all the way to the right. Be careful not to write over the existing variable; if you do, click Cancel and try again. Add a semicolon and the path to your *python.exe* file to the existing variable:
68+
69+
%SystemRoot%\system32\...\System32\WindowsPowerShell\v1.0\;C:\Python35
70+
71+
Close any existing terminal windows, and open a new one. Now when you enter **python --version**, you should see the version of Python you just set in your `Path` variable. You can now start a Python terminal session by just entering **python** at a command prompt.
72+
73+
<a name='installing_geany'></a>Installing Geany
74+
---
75+
76+
You can download a Windows installer for Geany from [http://www.geany.org/Download/Releases](http://www.geany.org/Download/Releases). Download and run the installer called *geany-1.25_setup.exe*, accepting all the defaults.
77+
78+
[top](#)
79+
80+
<a name='configuring_geany'></a>
81+
### Configuring Geany
82+
83+
If you use the simple command `python` to start a terminal session on your system, you shouldn't have to configure Geany at all. But if you use a command like `python3` or a full path like `C:\Python35\python` to start a terminal session, you'll have to modify Geany slightly so it uses the correct version of Python to run your programs.
84+
85+
Open an empty file and save it as *hello_world.py*. The file should have one line in it:
86+
87+
print("Hello Python world!")
88+
89+
Go to **Build>Set Build Commands**. You should see the word *Compile*, and a command next to the word *Compile*. Change this to
90+
91+
python3 -m py_compile "%f"
92+
93+
You can also use a full path in this setting, such as `C:\Python35\python -m py_compile "%f"`.
94+
95+
Next to the word *Execute*, enter the following command:
96+
97+
python3 "%f"
98+
99+
Again, you can use a full path, such as `C:\Python35\python "%f"`.
100+
101+
Now you can run programs by selecting **Build>Execute**, clicking the Execute icon with a set of gears on it, or by pressing **F5**.
102+
103+
[top](#)
104+
105+
106+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
message = "One of Python's strengths is its diverse community."
2+
print(message)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
age = 23
2+
message = "Happy " + str(age) + "rd Birthday!"
3+
4+
print(message)

0 commit comments

Comments
 (0)