As mentioned in the Overview document, there are some advantages to downloading and running WinPython. In particular, with that version you can easily move your projects among different computers. However, if you don't need to do that and you are running Windows, you may find it advantageous to download and install Python and then download and install the appropriate packages for the Python Scientific Computing Ecosystem.
Among other advantages, this will provide more control over where you store your Jupyter Notebook documents. It may also run faster than WinPython running on a USB device.
This document provides instructions for building your Python scientific system from scratch on a Windows machine.
These instructions will require you to do some command-line operations. If you are unfamiliar with the command line, you may find it useful to review the following web page: Getting to Know the Command Line.
Several of the instructions will tell you to open a command-line window in a particular folder. Here is an easy way to do that if you are running Windows.
Use a text editor such as Notepad or Notepad++ to create a batch file named aacmd.bat in the folder of interest. (Make sure the file is NOT named aacmd.bat.txt, which can happen sometimes with Notepad.) Put the following two lines of text in the file:
echo off cmd
When you double-click on that file in Windows Explorer, a command-line window should open in that folder similar to the one shown below. (If the double click simply causes the file to open, it probably has a hidden extension of .txt.)
You should only need to create the file once. Once you have created the file, you can copy it from folder to folder to open command-line windows in different folders.
Your computer must be connected to the Internet for any of the installations described in this document to be possible.
Here are the steps for downloading and installing Python on a Windows machine. (Note that these instruction purposely do not install the program in the default folder.)
At this point you should be able to open the folder named Python3xy and see that Python has been installed.
The following operations can be used to confirm a successful installation.
Much of the material that follows was taken from the following web pages: Installing Packages and Installing Jupyter Notebook. Take a look at those pages for help if you experience problems.
Open a command-line window in some arbitrary folder and enter the following command:
python --version
This should produce an output on the screen similar to the following:
Python 3.6.4
Ensure you can run pip from the command line by entering the following command at the command prompt:
pip --version
This should produce an output similar to the following:
pip 9.0.1 from c:\programfiles\python364\lib\site-packages (python 3.6)
Ensure pip, setuptools, and wheel are up to date by entering the following command at the command prompt:
python -m pip install --upgrade pip setuptools wheel
This will produce several lines of output text that should end with something like the following:
Successfully installed setuptools-38.4.0 wheel-0.30.0
Ensure that you have the latest version of pip by entering the following command at the command prompt:
pip install --upgrade pip
If pip is up to date, you should see something like the following:
Requirement already up-to-date: pip in c:\programfiles\python364\lib\site-packages
Otherwise you should see an output indicating that the latest version is being installed.
At this point you should be ready to use pip to install packages to supplement the basic Python system.
Before continuing, you should view the following three videos for an introduction to the Jupyter Notebook:
To install the Jupyter Notebook code, open a command-line window in an arbitrary folder and enter the following command at the command prompt. (The folder choice doesn't matter at this point because the Windows OS already knows where the required material is located.)
pip install jupyter
This will cause the pip program to download and install the latest version of the Jupyter Notebook from PyPI - the Python Package Index or perhaps some similar online archive.
This may take a while to complete while producing a large amount of output text on the command-line screen. Eventually the command prompt should return. If you open the Scripts folder in the Python3xy folder after the command prompt returns, you should see many files related to the Jupyter Notebook including a file named jupyter.exe.
You can confirm your Jupyter Notebook installation by creating and executing a very simple Python program inside the Jupyter Notebook.
Open a command-line window in the folder where you plan to store your Jupyter Notebook documents and enter the following command at the command prompt:
jupyter notebook
You should see a lot of text appearing in that window and the jupyter notebook should open in your browser.
Open the New drop-down list in the upper right and select Python 3.
Enter the following code in the first cell:
print("Hello, World!")
Select the Kernel tab and then select Restart and Run All.
Select Restart and Run All Cells in the window that opens.
The following text should appear inside the cell immediately below the command indicating that you have successfully installed both Python 3 and the Jupyter Notebook.
Hello, World!
When you are satisfied with the results, do the following:
At this point you cannot run any code that requires libraries (such as matplotlib) that are not included in the standard Python distribution because you haven't installed any packages containing such libraries.
Open a command-line window in an arbitrary folder and enter the following command at the command prompt to download and install the latest version of the matplotlib library. This command will also download and install the latest version of the numpy library.
pip install matplotlib
After some time, the command prompt should return and matplotlib will have been installed. You should see a folder containing matplotlib at the following location:
C:\ProgramFiles\Python364\Lib\site-packages\matplotlib
You should also see a folder containing numpy at the following location:
C:\ProgramFiles\Python364\Lib\site-packages\numpy
You can test your installation with a script that requires the matplotlib and numpy libraries in addition to the standard Python libraries.
Copy the following code into a text file named proj01.py in an arbitrary folder:
import numpy as np import matplotlib.pyplot as plt import math fig,axes = plt.subplots(2,2, figsize=(7,5), facecolor='0.75', linewidth=10, edgecolor='Red') t = np.arange(0, 6.0, 0.05) ax0,ax1,ax2,ax3 = axes.flatten() ax0.plot(t, np.cos(1*np.pi*t)) ax0.set_ylabel('This is a ylabel') ax0.set_xlabel('This is an xlabel') ax0.set_title('A cosine') ax1.plot(t, np.exp(-t) ) ax1.set_ylabel('This is a ylabel') ax1.set_xlabel('This is an xlabel') ax1.set_title('An exponential') ax2.plot(t, np.exp(-t) * np.cos(3*np.pi*t)) ax2.set_ylabel('This is a ylabel') ax2.set_xlabel('This is an xlabel') ax2.set_title('A damped cosine') ax3.plot(t, np.exp(-t) * np.cos(4*np.pi*t),label='Damped cosine') ax3.plot(t, np.cos(4*np.pi*t),label='Cosine') ax3.legend(loc='upper right',framealpha=0.3,facecolor='Green') ax3.set_title('Subplot with a legend') ax3.set_ylabel('This is a ylabel') ax3.set_xlabel('This is an xlabel') ax0.grid(True) ax1.grid(True) ax2.grid(True) ax3.grid(True) fig.suptitle('A figure title') fig.tight_layout(pad=2) plt.show()
Open a command-line window in that same folder and enter the following command:
python proj01.py
This should cause the image shown below to appear on your screen.
You can use the same code to test Jupyter Notebook in conjunction with the newly installed libraries.
The same image should appear immediately below the code except that it won't have the seven buttons along the bottom.
While you are at it, you should probably go ahead and execute the following three commands at the command prompt to install the pandas, seaborn, scipy, and pillow libraries. You will need these libraries in this or the follow-on courses. You will learn about the first three later. The pillow library must be installed if you need to write output files in the jpeg format.
pip install pandas pip install seaborn pip install pillow
You may also discover other libraries that you will need to install as you progress through this coursework. If so, you should be able to use the knowledge gained here to do the installations.
If you have made it to this point, you have learned most of what you need to know to create your own Python development environment containing many of the packages that are freely available on the web. Some useful resources for you to study are listed below:
Author: Prof. Richard G. Baldwin
Affiliation: Professor of Computer
Information Technology at Austin Community College in Austin, TX.
File:
BuildingPythonFromScratch.htm
Revised: 04/24/18
Copyright 2018 Richard G. Baldwin
-end-