Getting Started

These notes are for Python running in Windows OS.   Not intended to be helpful if you run iOS or Linux.  

Install Python

Download and install Python.   Do NOT put Python in your Windows OS path.  

Create a Python Project Folder

Create a new empty folder that will hold your Python project (code).   Typically this will reside in a folder off of your 'My Documents' folder.   This example will use the project folder name 'proj_py'.  

Decide on a Python Version

Browse the folder below and look at the subfolders.   Each installed version of python will be in it's own folder, with the name 'Python' followed by the version.   Ex. 'Python27', 'Python38-32'.   Decide what Python version you intend to work with and remember that reference as '#.#'.   You can see the current status of Python versions at: devguide.python.org/versions.  


C:\Users\[Your Windows User Name]\AppData\Local\Programs\Python\

py --list-paths

Update PIP

PIP is Python package manager.   You probably installed several packages with PIP at this point.   The following steps will clear out all installed packages so that you can begin fresh and build a clean virtual environment.   Open a Windows Command Prompt and navigate to the 'Scripts' folder where it resides:


C:\Users\[Your Windows User Name]\AppData\Local\Programs\Python\Python38-32\Scripts\

Then from the Windows Command Prompt execute the command 'pip --version' to confirm that pip is installed.  

Upgrade pip to the latest version.   From the Command Prompt:


py -3.8 -m pip install --upgrade pip

Now execute the commands below from your project folder.   The first will create a text file named 'reqs.txt' that lists all of the Python packages installed.   The second command will use the 'reqs.txt' file to uninstall all of those Python packages.  


py --list-paths
py -m pip freeze > reqs.txt
py -m pip uninstall -y -r reqs.txt
py -m pip list

You may close the Windows Command Prompt.  

Setup Virtual Environment

Open a new Windows Command Prompt and navigate the working directory to the folder where your project resides ('proj_py').   Execute the command below, substituting the '3.8' for the Python version you wish to use for your virtual environment (it may take some time till the command is completed).   Also execute the next two commands to activate the virtual environment, and to show (and confirm) the Python version it was configured for.  


py -3.8 -m venv env
env\scripts\activate
py -V

After you execute the command 'env\sripts\activate', the command prompt will have '(env) ' added to the beginning of it, confirming that you are now working in a Python virtual environment.  

Install Python Packages

Install the Python packages you wish to use in the Virtual Environment you created for your project by using the command:


py -3.8 -m pip install [package name]

When you are finished installing packages, verify they are installed properly by using the PIP command:


py -m pip check
py -m pip list

Build requirements.text

When all packages have been installed, build a requirements.txt file.   This file makes it easy to share the current Python configuration with someone else, and to instantly open this project and start working with the same configuration as the last time you worked on it.  


py -m pip freeze > requirements.txt

Ending The Project Session

Terminate the virtual environment by executing the following command from the Windows Command Prompt:


venv\scripts\deactivate

Note that the Windows command prompt will change, and the '(env) ' will no longer be shown.  

Verify that the added package is not installed into the global PIP by executing the command:


py -m pip list

ReStart a Project Session

Open a Windows Command Prompt and change the working directory to the folder where the project resides (and the requirements.txt file exists).   Execute the command below.  


env/scripts/activate

Execute the command below, and you will see the Python modules you installed within the virtual environment available.  


py -m pip list

If you need to install more Python packages, make sure to do it with the virtual environment activated.   Then when all is installed and working, repeat the command below to update the 'requirements.txt' file.  


py -m pip freeze > requirements.txt