Setting Up A Development Environment For Python¶
The following is the recommended setup for the UWPCE Python Certificate Program. It is not necessary to have exactly this same setup, but if you choose to use a different setup, we will be less able to support you if you need help.
Minimal Setup¶
Although it is OK to use different tools, there are some requirements to successfully do the work the program requires:
- cPython version 3.6.* or 3.7.*
- A way to edit Python files (Programmers Text Editor)
- A way to run your code – command line, IDE, etc.
- A way to use the “git” source code version control system
You can be successful in the program as long as you have the above. If you don’t already have a setup that fulfills those requirements – read on.
Platforms¶
Python is a very platform independent system, it can run on all major operating systems, including micro controllers even. It is most commonly used in production on Windows, Linux or OS-X systems.
For this program, we feel it is best for students to work in an environment in which they are comfortable, and which they will ultimately use to do production work.
We have included instructions for Windows, Linux and OS-X systems – any of these are fine.
Python Itself¶
Python is a “byte compiled, interpreted” language. What this means to you is that you need a Python interpreter to run your Python code. It also means that that is all you need – write some code, and run it with Python. That’s it.
There are a number of different Python interpreters (or run-time environments) available:
- cPython
- PyPy
- Jython
- Iron Python
- MicroPython
These each have their own special uses. For example, for interaction with the Java VM or Microsoft CLR, or running on micro controllers. But most production Python is run with the cPython interpreter, and most people mean cPython when they say “Python”.
For this program, you will need cPython version 3.6, installed and running so that when you type “python” at your command line, it starts up.
cPython itself is available from a number of sources, or “distributions”. We recommend the version available from python.org.
Python is also available as part of the Anaconda data analysis environment, as well as a few other sources. These Python distributions will work fine for this class, but when we get to advanced topics like virtual environments, there are some differences – and you will be responsible for adapting to these differences.
Your Development Environment¶
There are three basic elements to your environment when working with Python:
- The Command Line
- The Interpreter
- The Editor
- The source code version control system
Some folks use an Integrated Development Environment (IDE), which combines some or all of these functions. For this class, we don’t recommend using an IDE, because while it can make some things easier, it can also hide things that will be good for you to understand.
Minimal Requirements¶
In order to be productive in this program, you need to be able to do the following:
- Manipulate files and write and save Python code in files. You really, really want a “real” programmer’s editor for this.
- Run your code with Python 3.6 or 3.7
- Run the iPython interactive interpreter
- Install new packages with pip
- Use the git source code management system (with gitHub)
If you are not set up and comfortable with doing all that, read and follow these instructions:
Installing Python and core tools
Then come back and follow the rest of this review.
The Command Line (cli)¶
Having some familiarity with the command line is important
Familiarity with basic use of the command line is a prerequisite for the program, so we won’t cover this much in class. If you are not comfortable with the command line, please bone up on your own.
We have some resources here: Command line basics
We suggest running through the cli tutorial at “learn code the hard way”:
Or, for Linux and OS-X users:
Linux command line for you and me!
Windows:¶
Most of the demos in lessons will be done using the “bash” command line shell on OS-X. This is identical to the bash shell on Linux.
Windows provides the “DOS” command line, which is OK, but pretty old and limited, or “Power Shell” – a more modern, powerful, flexible command shell.
If you are comfortable with either of these – go for it.
If not, you can use the “git Bash” shell – which is much like the bash shell on OS-X and Linux: Terminal
Or, on Windows 10, look into the “bash shell for Windows” otherwise known as the “Linux subsystem for Windows” - - more info here: Using Windows Bash for Python Development
OS-X¶
OS-X comes out of the box with a bash command line. You can access it by running the “Terminal” application, which you can find under:
Applications => Utilities => Terminal.app
Drag and Drop it into the dock for easy access.
The Terminal app can be interfaced with the Finder, making it easy to open it up with the working dir set to the current folder in the finder:
See: launch an OS-X terminal in a folder
for how to set that up.
Linux¶
On Linux, the terminal is usually very accessible – each Desktop System has a different way to access it – figure out how on your machine.
The Python Interpreter¶
Python comes with a built-in interpreter.
You see it when you type python
at the command line:
$ python
Python 3.6.1 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
That last thing you see, >>>
is the “Python prompt”.
This is where you type code.
Python in the Interpreter¶
Try it out:
>>> print("hello world!")
hello world!
>>> 4 + 5
9
>>> 2 ** 8 - 1
255
>>> print ("one string" + " plus another")
one string plus another
>>>
To get out of the interpreter, you can type:
exit()
Or hit ctrl+D on Linux and OS-X or ctrl+Z On Windows.
Tools in the Interpreter¶
When you are in the interpreter, there are a number of tools available to you.
There is a help system:
>>> help(str)
Help on class str in module __builtin__:
class str(basestring)
| str(object='') -> string
|
| Return a nice string representation of the object.
| If the argument is a string, the return value is the same object.
...
You can type q
to exit the help viewer.
You can also use the dir
builtin to find out about the attributes of a
given object:
>>> bob = "this is a string"
>>> dir(bob)
['__add__', '__class__', '__contains__', '__delattr__',
'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
'__getitem__', '__getnewargs__', '__getslice__', '__gt__',
...
'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines',
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper',
'zfill']
>>> help(bob.rpartition)
This allows you quite a bit of latitude in exploring what Python is.
Advanced Interpreters¶
In addition to the built-in interpreter, there are several more advanced interpreters available to you.
We’ll be using one in this course called iPython
Some information about iPython can be found here: iPython Interpreter
The Editor¶
Typing code in an interpreter is great for exploring.
But for anything “real”, you’ll want to save the work you are doing in a more permanent fashion.
This is where an Editor fits in.
Text Editors Only¶
Any good programmers text editor will do.
MS Word is not a text editor.
Nor is TextEdit on a Mac.
Notepad
on Windows is a text editor – but a poor one.
You need a real “programmers text editor”
A text editor saves only what it shows you, with no special formatting characters hidden behind the scenes.
Minimum Requirements¶
At a minimum, your editor should have:
- Syntax Colorization
- Automatic Indentation
In addition, great features to add include:
- Tab completion
- Code linting
- Jump-to-definition
Have an editor that does all this? Feel free to use it.
If not, we recommend SublimeText
:
Turning Sublime Text Into a Lightweight Python IDE
“Atom” is another good open source option.
Turning Atom Into a Lightweight Python IDE
“Visual Studio Code” is a relatively new cross platfrom offering from Microsoft – a lot of folks seem to like it:
Using Visual Studio Code as a lightweight Python IDE
And, of course, vim or Emacs on Linux, if you are familiar with those.
Why No IDE?¶
An IDE does not give you much that you can’t get with a good editor plus a good interpreter.
An IDE often weighs a great deal.
Setting up IDEs to work with different projects can be challenging and time-consuming.
Particularly when you are first learning, you don’t want too much done for you.
Why Not an IDE?¶
That said …
You may want to go get the educational edition of PyCharm:
https://www.jetbrains.com/pycharm-edu/
Which is awesome.
Here are a number of pages to help you get started:
Version Control System¶
While not strictly necessary to develop code, it is a very, very good idea to manage your code in a Version Control System:
https://en.wikipedia.org/wiki/Version_control
This is such a critical software development practice the we use it in the program for you to mange your projects and turn in assignments, so that you can gain familiarity with the practice.
git¶
git (https://en.wikipedia.org/wiki/Git) is an open-source version control system that has become an industry standard – very widely used in both commercial and open-source development.
We will be using git and the web service gitHub for collaboration in this program.
Make sure you are set up to use git on your machine. If you have using a command line client, you should be able to type:
git --version
and get something like this as a response:
git version 2.11.0 (Apple Git-81)
Am I ready to go?¶
To see if you have Python ready to start class, try the following:
Create and run a Python “program”:¶
Create a file called install_test.py
, with the following content:
import sys
print("This is my first python program")
version = sys.version_info
version_string = "{}.{}".format(version.major, version.minor)
if version.major == 3:
if version.minor not in (6, 7):
print("You should be running version 3.6 or 3.7")
else:
print("You are running python{} -- all good!".format(version_string))
else:
print("You need to run Python 3!")
print("This is version: {}".format(version_string))
Run it with your version of python. It should result in:
This is my first python program
You are running python3.7 -- all good!
If you get something else – figure out why and fix it!
Run git¶
You should be able to run git on the command line:
$ git --version
git version 2.20.1 (Apple Git-117)
It should be version >= 2
iPython¶
iPython
is not critical, but it is very nice. You should be able to run it with:
$ ipython
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.
And get something like that.
ipython
can be quit by typing quit
Specific Documentation¶
- Turning Sublime Text Into a Lightweight Python IDE
- Turning Atom Into a Lightweight Python IDE
- Using Visual Studio Code as a lightweight Python IDE
- Command line basics
- Shell Customizations for Python Development
- iPython Interpreter
- Using Windows Bash for Python Development
- git Overview
- Feature Branching
- Working with Virtualenv