In this section I will give some notes about how I set up Python on my computer. This process is tedious and boring, much like doing taxes. If you have never set up Python before, these notes might be enough to point you in the right direction, but you will probably have to head over to Google or YouTube to find much more detailed explanations and find what works best for you.
Additional warning: the steps below are simply the setup steps I took. It's not necessarily the "best" way, and certainly not the "only way", so YMMV (Your Mileage May Vary).
Head over to python.org/downloads. Available releases are listed in order from newest to oldest. Pick a release. On the release page, download the Windows Python install manager. When the download finishes, run the install manager on your computer.
What does it mean to "install Python"? In simple terms, it means that you have installed components into your computer which are able to interpret the Python language and translate it into machine language instructions for your computer to execute.
Python is an interpreted language. With Python installed, you can open up a terminal window (e.g. Windows Command Prompt) and start the Python interpreter. Then, you could start entering in Python statements and the computer will execute each line you enter. Or, you could write a sequence of Python statements into a file, and then ask the interpreter to run the file.
Some education courses introduce programming to students with a language called C. C is a compiled language, meaning that you write a series of statements, then send the statements through a compiler, and then ask the computer to execute that compiled code.
The fact that Python is an interpreted language, as a compiled code, makes it easier for beginners, in my opinion.
Python comes with lots of “off-the-shelf” functionality. When you install Python, it comes with what we may call the "standard library" of functionality. For example, off-the-shelf Python comes with functions for things like reading and writing files, doing math, and manipulating strings. As we mentioned in the previous section, the standard library can be expanded by adding in additional packages or libraries made by the Python community. The place where these packages live is called the Python Package Index.
The tricky thing about adding in additional libraries is that they can have complex interdependencies and versions. Therefore, to reduce the amount of headaches in your life, it is good practice to make dedicated "virtual environments" for each project you start, and install packages into those environments instead of into your "base" installation. This way you can have multiple different projects on your computer, each with its own set of addon packages and versions, and not have to worry about sorting out version and dependency conflicts.
There are many ways of setting up a virtual environment. I will list mine but it's best to do your homework instead of trying to copy what I did. Read what people say on the internet and pick the best option for what suits your situation.
My setup is:
use pip to install libraries called virtualenv and virtualenvwinwrapper-win into my base python installation
create a virtual environment for my new project using the above two libraries
activate the new virtual environment and then use pip to install whichever libraries from PyPi as desired
Note that you can see which libraries are installed in the virtual environment using pip list, and it's good practice to save this list to a file called requirements.txt so that your environment can be more easily recreated on another computer or in the future. A file containing the full list of packages present in the project environment can be obtained by entering the command pip freeze > requirements.txt into a terminal window. The list will include the version of each package.
As projects develop, their code may become complicated. Version control is like “quick save” in video game; it gives you a spot you can revert to if you mess up your code. Version control is also really helpful if you want to work on a project with multiple people and on multiple computers.
Furthermore, with services like GitHub or GitLab you can create a free account and store a repository of your project online, so if you accidentally drop your computer, you don't lose all your hard work.
Some tips for beginners:
If you don't want to learn command line instructions for running git on your computer, you can download desktop applications from GitHub or GitLab that give you a graphical interface for managing your project.
When you create a project repository, you can choose to make it public or private. Lots of people enjoy working on publicly shared projects; I prefer to keep most of mine private. The main reason for this that for personal projects, having the code publicly visible will cause me to spend too much time anticipating questions or objections viewers might have. I prefer to explain projects by writing and illustration, rather than having people read my very average code.
When developing, you may generate a lot of temporary files like output files or troubleshooting notes. You can create a .gitignore file to tell git to ignore these files from version control, to avoid cluttering your repository.
I like developing ideas by first writing code in Jupyter Notebooks. I installed Jupyter Notebooks in my project virtual environment by running pip install jupyter. To start a new notebook I would do the following:
start terminal
activate the project's virtual environment
enter jupyter notebook which will open up the Jupyter Notebook application in a web browser like Chrome
Click New Notebook
For projects, my code writing process usually goes something like this:
develop a rough idea by writing and running a code sketch in a Jupyter Notebook
once the idea is well developed, create a python module (.py file). Using a code editor, rewrite the code in a cleaner way in the module
import the module content into the Jupyter notebook and then develop some more ideas
Over time this process results in having a growing collection of exploration Notebooks and python modules (.py files).
One final tip: when committing ("saving") Jupyter Notebooks to git, use Edit > Clear Outputs of All Cells just prior to saving the Notebook. This will keep the file sizes down to a few kilobytes.