Python is one of the fastest-growing programming languages nowadays and is used for machine learning, data science, and a lot of other use cases. The best way to start learning python is by practicing it on your machine.
We need to install python on your machine first. Once installed, you can run the python code on your machine. In this post, Let’s see how we can install python and run python code.
- Installation On Windows
- Installation On Mac Os
- Installation On Linux
- How to run python code
Installation On Windows
Sometimes your laptop may come with python installed and you can check by opening a command prompt and do
python -V. If you are seeing the below error, it means python is not installed on your machine and you can continue with this tutorial.
There are two versions of python out there 3.7(latest) and 2.7. Let’s go to this page and download the version that you want.
You can download any version But, most of the recent python apps are on python 3 and python 2 support is ending soon. For those reasons, let’s download python 3. Once you click on that link and you will be redirected to the below page and download the executable depending on your machine.
When you double click on this, a popup window is shown like below
You can check the second checkbox
Add Python 3.7 to PATH so that you can use it directly without any path specified. Once you click on the Install Now and you will see the following screens.
Now we can check the python version by opening a command-line interface. Make sure you are checking with capital V.
Installation On Mac Os
Installing python on Mac OS is no different than above. Let’s go to this page and download the
macOS 64-bit installer.
Once you download the installer, double click on it and follow the instructions like below.
Now we can check the python version by opening a terminal. Make sure you are checking with capital V.
One thing we can notice on Mac OS is that there are two versions installed: one is
2.7.15 and another one is
3.7.4. You can check and run those with the commands
Installation On Linux
There are so many Linux distributions out there. The following commands are for Ubuntu. Once installed you can verify the installation as same as above.
sudo apt-get update
sudo apt-get install python3.7
How to run python code
There are a couple of ways to run the python code: one is to use python interpreter and another one is to run the python file which ends with .py extension. Let’s see both ways below.
- Python Interpreter
- With .py extension files
python interpreter comes with the python installation and all you need to type
python in the command-line interface or terminal to use it. If you want to exit, just type
With .py extension files
I have put the same code in the app.py file and run this
python app.py in the visual studio code. Here is the output.
This is a very good starting point for anyone starting python for the first time. Once you know how to install, run python code, and necessary packages like PIP and virtualenv, all you need to go to the official website and practice the syntax and basics of python.
This brings the end of this Blog. We really appreciate your time.
Hope you liked it.
Do visit our page www.zigya.com/blog for more informative blogs on Data Science
Keep Reading! Cheers!