Category Archives: win10 environment variables

STARTING WITH PYTHON3 – The very beginning – V2

Journal: uffmm.org,
ISSN 2567-6458, July 5, 2019
Email: info@uffmm.org
Author: Gerd Doeben-Henisch
Email: gerd@doeben-henisch.de

CONTEXT

This is an update of the post ‘STARTING WITH PYTHON3 – The very beginning‘ from July-1, 2019. The original version was not ‘wrong’, but it seems, after a few days later, one can and should improve it. The main motivation for this new version is my experience as a linux programmer working with windows 10: learning by doing I detected a litle more radical approach to begin python programming with win10. This post is part of the overall  topic ‘Co-Learning with python 3‘.

OVERVIEW

In this updated version I will introduce some bits of the win10 environment which you will need for your python programming. Then I demonstrate the very first steps with some lines of code. Very important for all your own activities: in the beginning get you a helpful book to guide your start. After trying many sources I have actually the following recommendations:

  • Mark Lutz, Learn Python, 2013,5th ed.,Sebastopol (CA), O’Reilly
  • To get the sources: https://www.python.org/
  • Documentation: https://docs.python.org/3/
  • Python Software Foundation (PSF): https://www.python.org/psf-landing/
  • Python Community: https://www.python.org/community/

THE WIN10-ENVIRONMENT

When you start programming  you need a direct knowledge about your computing environment, in that case the win10 operating system. While linux is built up with an open mind and tries to make everything transparent, win10 is somehow the opposite: it is a closed box, and to work with it in direct contact with the operating system is not very well supported. Thus to work as a programmer with win10 is not what you ideally want. But now we are there and have to get the programming done.

After my first expriments with win10 I detected the following tools as very helpful to start programming: (i) The editor for the system and environment variables and (ii) the powershell. These tools allow you to define the operating system environment for your python programming  in a minimal way.

The editing of the system and environment variables you can reach by the following key-operations:

Editing System and Environment Variables

  1. Hit the windows key together with the key for ‘R’
  2. This opens a small window with a textfield-entry.
  3. In this field you enter the string ‘control’
  4. This opens a page with different topics for to manipulate some aspects of your system (because my computer is in the German-Mode I have the heading ‘Einstellungen des Computers ändern’, something like ‘Change options of the computer’).
  5. Here you select the topic ‘System and Security’
  6. Then another page opens with several topics, one is ‘System’, which you should select.
  7. On this new page you can see at the left border some more topics. The last one mentions something like ‘Extended System Options’. Select this
  8. Before you see the next page you will be asked to enter the Super-User Password. Thus you must be super-user to do this.  To be a real programmer you must have this rights to get a full understanding of what is going on.
  9. Then  the editor for system and environment variables pops up:
Editor for system and enviroment variables

 

  1. The interesting button is in the right down corner, in German: Umgebungsvariablen (‘environment variables’)
  2. Click this button and you will finally see the editor you are looking for:
Finally the editor to edit private and environment variables
  1. For the upcoming actions we need only the path-variable. One can highlight the Path-entry and select it with ‘Editing’ (German: ‘Bearbeiten’):
The window showing all the entries of the path-variable.
  1. Now you can see all the entries of the path variable nicely ordered one after the  other. This is a special service because the path-variable as such (as you will see later when using the power-shell) is one string. Here this string is splitted up into the different sub-strings. This allow you to add some new string or — also very important — to delete a substring. As You can see in the figure there is as last line an entry including the name Python . This line is the whole directory path on the drive C:\ where my actual python version is stored.

CLEAN UP BEFORE

Now, if You know where and how you can edit the basic system variables it can be a good idea to clean up the whole system with regard to older python installations. In my case I had tried  before — as a complete newbie — several python distributions like WinPython and Anaconda in different versions at different locations in the system, this accompanied with different installations of the python language. You can imagine that this caused finally some confusion what is where and what is causing which  effect.

Thus I decided to start from scratch, removing all the old stuff to get a ‘point zero’ for beginning.

The first step was to use the win10 explorer program with the find option in the small text-field up right.

Part of the win10-explorer window showing a find-operation on the whole PC

After you have entered your search-string, in this case ‘python’, you have to say (left up corner) the region, in which you want the search to happen. I have selected the whole PC.

After some while you see all locations as a complete path where the search-string python could be found. When I started my clean-up action there where lots of locations with different python installations, now there is only one left, which I am actually using.

But caution: If you want to delete the old installations you have (i) to look to the uninstall options/ programs to activate these to remove all stuff; (ii) finally you have to enter the editor for system and environment variables (see above) to delete all entries there, which are now obsolet.

GET YOUR PYTHON

Now, if you have set everything with Python to zero get your python version from the python home page: https://www.python.org/.

This page is a bit confusing. Stay cool. You can detect a field with the header Downloads and a hint to the latest version. In this case it shows 3.7.3. Click this.

Python Home Page for Downloads

The next page is completely confusing. The interesting part of this page is somewhere in the middle listing the different download files:

List of download files

We are interested in the 32-Bit version although I am working on a 64-Bit machine. For the learning the 32-Bit version is more flexibel and completely sufficient.

If you click the windows installer for python (second line from below) then a download notice will be shown asking for confirmation:

Confirm download of python installer

Select ‘datei speichern’ (download file) and the installer will be  loaded in your download directory.

In the list of files you can also see   a colum with the MD5-Checksum. This is an offer to check whether the file you have downloaded is indeed not corrupted in some way (viruses etc.) To use the MD5-Checksum code You need a MD5-software tool. I found a good description at this site: https://www.it-administrator.de/downloads/software/197801/, which points you to the following product page: https://www.novirusthanks.org/products/md5-checksum-tool/.

This looks quite OK. But if you want to apply it you have to surround some difficulties when you try to search for your file to check with the directory browser. In my case it shows the directory of the super-user first. To get my python download file I have to select the main drive C:\, there I have to select from Users my actual role as user gdh, and then I can find my download folder with the python exe file to be checked. From the web site with the files list I have copied the MD5-Checksum:

MD5-checksum tool at work

Luckily the check looks good. This encourages to install python 3.7.3 by clicking on the python installer.

Python Installer Window

Because I have already installe python I can only modify it or repair or uninstall. If you click it the first time you will be able to select the option Install. In that case it will propose a directory and it will install python. Before You say Yes You can also click the flag ‘Set Path Variable‘. I did this but the interesting point is that it had no effect when using the power shell (see below). Only when I added the path again with the aid of the powershell it took effect.

USING THE POWERSHELL

To get the powershell you have to press the windows button, then a list of Apps (programs) appears. Under the letter ‘W’ you see the windows powershell. Clicking this topic you will detect several versions of the power shell: 64-Bit and 32-Bit (indicated by (x86)), and the old standard version as well as a more enhanced version called integrated script environment (ISE).

I have started with the old, simple standard version. By right-clicking with your mouse you can add the option to attach the powershell to the task bar which makes it easy to call it up again later.

Section of my task bar including icons for normal powershell (left) and integrated script environment (right)

If you click on the powershell icon the powershell window will open:

Powershell window with the command python entered

If you would confirm this command by pressing the enter key — and you would not have set the path variable with the path of the python executing modul python.exe before — then there would appear a message that the command ‘python’ is not known (I cannot demonstrate it here because I have set the path variable on account of this message meanwhile).

There exists a workaround without setting the path variable explicitly by give the whole path of the python modul, like this:

Powershell calling python with explicit path

You see, this works fine. To make life easier I have set the environment path variable with this python execution path. Then you can enter the command python alone and a python environement opens up.

But, wait a moment. Setting the path variable with the editor for the environment variable alone (see above) this has no effect for the powershell! Also the powershell can show the content of the path-variable correctly:

Powershell showing content of path-variable

(This is the version of the path variable after I have added the path with the powershell too!)

To add the path variable for the python modul explicitly in the powershell you can enter the following  command:

PS C:\Users\gdh> $Env:PATH +=”;C:\Users\gdh\AppData\Local\Programs\Python\Python37-32″

When I did this everything worked fine. Don’t ask, why it didn’t work before with the editing of the environment variable PATH alone.  This is at a first glance like ‘Software mystik’. With much more time for research there exists perhaps an explanation. My first guess would be, that the communication between the powershell and the environment variable has some hidden factors. For more very detailed explanations about the powershell and the editing of the environment variable you can find a good document from microsoft here: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6.

PROGRAMMING PYTHON

For first programming steps look to the first version of this post beginning at the header FIRST PROGRAMMING STEPS somewhere in the middle of the page.

More coding will follow soon.