Wednesday, February 27, 2019

PyTips – Python For Windows

pytips-python-for-windows-header-image

Total beginners guide to Installing

& using Python For Windows

In this occasional series of guides for complete beginners to Python, I intend to avoid a common trap that seems prevalent in Python tutorials, and that is not to over complicate things.

All I wanted when I first started out, was the quickest and simplest way to get started.  What is the point in overloading a new user with a ton of confusing possibilities at this stage?

Note: you can skip to the Download Python section, ignoring the next four paragraphs, if you are in a rush to get started.

My way of thinking is to get up and running, and then learn about fine detail later. This tutorial will be the “up and running” bit that you need to get started with Python.

Once you have your “hello world!” program running, you can then start learning about things like a different IDE (personally I like the simplicity of IDLE, it’s built in, and free), or virtual environments, which I don’t bother with, as its just adds a confusing layer of  complexity for a beginner, especially if they have never used venv’s before.

Yes, It’s all very well simplifying things, but there will always be stuff that needs to be mentioned for this to be a worthwhile tutorial. To get around this, I have added further relevant information in the form of tips, which I have coined as “PyTips” (for some unfathomable reason!), mostly at the end of this page.

First I show the quickest and simplest way of achieving our objective. And then some tips.  I will point out what tips are important to note right now.

1. Download Python

OK, let’s do it then.  Our first step is to download Python itself.

Click on this link to go to the Python download page.

If you want it really simple, just download the package offered for your computer, which will be the latest release, and you will be fine. Click the big yellow button.

Installing Python For Windows-python-windows-download-page

But, see PyTip #2 and PyTip#3 and PyTip#4 below, if you don’t mind faffing about a little. You can skip these three tips if you are in a hurry, or don’t need or want too much detail at this stage.

Click on “Save File“, or the equivalent, in your browser. I use Firefox here, I would hope you know how to use your chosen browser?

download-latest-python-firefox

Once its finished downloading, click on the downloads button in your Firefox toolbar (top right of browser), and then click on the file to open and install it.

firefox-download-button

2.Install Python

This is the first screen you should see on running the Python installer.

install-python-screen1

PyTip #1-Read This Now

Make sure you tick “add Python 3.7 to path“, or you will have to do it manually, which is a totally unnecessary inconvenience, just tick it bro, whatever version you are installing. I have no idea why it is not ticked as a default.

You can also change where Python is installed, and customise other options, see PyTip#5. My advice to a complete beginner is to just accept all the defaults for now.

Once you are ready, click on the “install now” button (it doesn’t look like a button really) and Python will do the rest. If all went well, you will see this screen.

python-sucessful-install

Click the “close” button and look in your program files from your Windows start menu to find the Python folder.

 

3.Running Python

You can run IDLE from there of course, but I prefer to drag and drop IDLE onto my desktop, for ease of access, (that’s up to you).

Double click on IDLE to run it (if you have moved the icon to your desktop) or select IDLE from your program files menu, and you will see the “Python shell” pop up.

Don’t worry about what this shell does just for the moment, we want the code editor, so in the drop-down file menu of the shell, select “new file“, (or hold down ctrl and press n on your keyboard), like in the image below.

idle-shell

You will now be presented with a blank editor window. I have customised the colours in my IDLE and the extra install in Python V3.7 that I did for this tutorial has used those settings, sorry about that. So yours will look a bit different than mine.

This is where we can type, or load in, source code, and run it.

idle-editor

4.Hello World!

Type, (or double-click on the code and copy and paste), the following line into the editor:(Ignore the line number)

print("hello world")

and then press F5 to run the program, (annoyingly IDLE forces you to save to disc before executing your code), and you should see the Python shell pop up and display whatever text is between the quote marks.

hello-world

5. Load Some Source Code

Now go to my Dropbox folder, where I have a collection of code snippets especially for beginners. I call them “Newb Code Snippets“.

I would start with the first snippet, “01-open a webpage in defaultbrowser.py“, because it’s a really simple bit of code anyone can play with that actually does something tangible.

Click on the link in my Dropbox and the code will be displayed on a separate page.

Now highlight all of the code by dragging your mouse pointer over it, and then right-click and select “copy”.  That code is now stored on your clipboard, ready to be pasted somewhere.

copy-snippet

Now paste the code into IDLE editor (not the shell), and then press F5 to run the program.

paste snippet

The code will open your default browser, and display the page at Google.com. Try changing the web address between the quotes to go to a different web site.

Now get stuck in with other code snippets that may interest you, and try to learn how they work from the comments in the code, and with googling what each separate statement does, there is a ton of help out there for Python.

 

6. Useful Python Beginner Resources

You can read about what each of my Newb Python Snippets do here: #1, #2, #3, #4, #5, #6, #7, #8,  #9 , #10  and #11

Ask for help at: Reddit learn Python , The Python Forum,  Stack Overflow  and Dreamincode Python forum

Free Python books: Automate The Boring Stuff is the most popular free Python book ever, there is also a list of dozens more here.

On YouTube there are thousands of Python tutorials, some good, some great, some really poor.

Google for anything else you need, you may be surprised at just how popular Python is.

7.PyTips

Following are the rest of my PyTips for this session, you can safely ignore them for now, but it could be worth just noting what they say for future reference.

PyTip #2. Don’t Get The Latest Python

The download Python page will offer you the latest version of Python for your computer. Don’t take it. Instead, hover over the “download” button in the menu, and click on “All releases”.

Now select a previous version of Python. For example, at the time of writing is V3.7.2. I use v3.6.5 as I like to stay behind the curve, here is why.

The latest version of Python is a work in progress, and does not support all the add on modules that you may want to use. It will eventually of course, but then it will move on to the next version, hence why I stay a version behind.

This won’t really affect an absolute beginner much, if at all, maybe some source code examples that you come across may not work, but that’s all.

PyTip #3. Get The 32bit version

Another thing to consider when downloading Python is the bit version to download. 32bit or 64bit? You may think that is a straight forward question to answer, well it nearly is.

For example. I have Windows 7, 64bit and what I have found is that for other people to use my executable programs they must also have a 64bit Windows machine if I use Python 64bit install, ouch, that’s a large slice of users I just cut out of using my programs.

The obvious solution is to install the 32bit version of Python on my 64bit machine, and then my .exe files run on virtually any recent Windows, though not Windows XP or earlier I’m afraid.

PyTip #4. Don’t use Python V2

There are still tons of tutorials and source code about that use Python V2. Some people won’t move on to V3, saying they prefer V2, which is fair enough, I’ll probably be like that when V4 comes out 🙂

But all support will end soon for V2, and it will be “deprecated“, which in Py-speak means “we want this software forgotten about asap“. For a beginner It’s really not worth the hassle of learning V2, and then having to re-learn parts of Python when you are forced onto V3. Just forget about V2, okay.

PyTip #5. Change Python’s location

The standard Python location is something like C:\Users\your_name\AppData\Local\Programs\Python\Python37-32, which to me is totally non-nonsensical, what is wrong with “C:\python37” or something similar?

This is the path I currently use for my Python installation, C:\python36″, and it works fine.  You can change where your Python is installed in the customise options of the installer.

PyTip #6. Python code is case sensitive

This is one of the very first things that tripped me up when I started out with Python. For example, If you type in:

Print(“hello world”)

instead of

print(“hello world”)

Python will throw an error, (because of the capital “P” in the word print, it should be a lower-case p).

 

That’s it for now, good luck in your PyQuest

 

I’m using Python V3.6.5 32bit, on Windows 7 64bit

 


I have also started another free blog of my personal Memoirs,  that nobody will be interested in, except maybe my son and my mum 🙂

“If one does not leave a record of one’s doings on Earth,  then what is the point of it all?”  Steve Shambles. Feb 2019

 

Advertisements


from Python Coder
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...