How to install and run Python, easily

Man Hay Hong
5 min readSep 27, 2018

--

People often suggest IDEs like Pycharm or web app like Jupyter Notebook, those are powerful tools for sure, but also quite heavy-weighted. Depending on your need, its always good to look for the right tool for the job.

If you are only looking to build simple Python projects on a personal level, such as a crypto trading bot, a script to send message with Telegram, or simply want to start feeling geeky, whats illustrated below might be more preferable.

If you are completely new to Python, you might also want to checkout this cool guide to learn Python basics in 15 minutes

This article also covers how to install Python libraries using PIP, as well as some common errors below

If you are using Mac or Linux

Use exit() to exit Python

No installation needed, Python is already built-in

To check, open up your terminal, enter python for Python2 or python3 for Python3

Changing directory (cd) to “Desktop”

Before running your Python file, it is very important you know where your file is located. Let’s say your Python file is saved in “Desktop”, you will first need to go to the “Desktop” directory in the terminal. Type in cd Desktop will bring you there

Finally, to run your file, simply enter python3 filename.py in the terminal.

By the way, you can write Python codes with any text editor, be it TextEdit on Mac, gedit on Ubuntu or NotePad on Windows. You just have to save the file with a name ending in .py and “All Files” as the type.

Save your file with .py extension, then run in the terminal: python3 filename.py

Learn more about terminal commands

If you are using Windows

Time to switch to Mac or Linux, then go back to the guide above

nah just kidding :)

Download Python from this page, pick “Latest Python3 Release”, then scroll to the “File” section, go for Windows x86 web-based installer and run the installer.

Tick the “Add Python 3.x to PATH” box, then proceed with “Install Now”.

Select the “Disable path length limit”, this will allow Python to use long path names, after this you are done with the installation.

Click here if you want to know more about path limit.

Now search and open up a Python shell, press Ctrl + n to open a new file, write your code, save the file, finally press F5 to run.

Useful shortcuts: Ctrl+n (Open a new file), F5 (Run the file)

Making your life easier

Make sure PIP is installed

PIP is a command you can use in Command Prompt / Terminal to install Python libraries, and libraries are basically what others have built and made available to everybody.

Usually PIP comes along by default if you are running Python 2.7.9+ or 3.4+

Search “cmd” on Windows to open a Command Prompt

To check, enter pip --version (or pip3 --version for Python3) in Command Prompt / Terminal

You can tell PIP is installed if a version is returned, if not, follow this guide to install PIP

To install a package with PIP, simply run the pip install <package_name> command, or pip3 install <package_name> for Python3.

For example, we will install the library “requests” with pip3 install requests below:

and just in case you want to learn more about the Windows command line

Beginner’s Frustration

would of course be bumping into a bunch of errors when running the code, but you have no clue what the heck is wrong

If you are from a business background, like myself, a rock-solid coding fundamentals is probably not your strength, so you’d probably ended up copying publicly available code on the web and try to run it when you see something interesting. And just when you are so excited to see what this piece of code can do for you, nothing more than an error is returned:

ImportError: No module named xxxxxxx

If this is what you see, it means that you are trying to import a library which you have not installed yet. So yes you would have to install the missing libraries by running pip or pip3 install <your missing library> just as shown above.

Another common error would be:

IndentationError: expected an indented block

or

IndentationError: unindent does not match any outer indentation level

Indentation is crucial in Python, as its how the language is structured. If your code is not indented with a correct format, its not possible to run. Refer to this guide for a detailed illustration on code indentation.

Image source: OREILLY

Pay attention to Spaces vs Tabs as well, only use either space OR tabs for indentations, mixing the 2 of them will result in errors

Of course there are myriads of other errors that can potentially occur, just turn to Google when that happens, you’ll find everything you need

Using a better editor

While it is possible to stick to default text editors just like the above examples, using an editor of your appetite can boost your efficiency. My personal favorite is Sublime Text, but feel free to also try these out and see which one suits you best.

--

--

Man Hay Hong

Finding the balance between Business and Tech. Crypto lover? Checkout: https://cryptodenada.com/. Need a website/app built? Checkout: https://denadahk.com/.