Using python
By Richard Porteous
Before installing Python first check if you already have it.
Depending on your operating system, follow these steps:
Windows: Press Win + R to open the Run dialog. Type cmd and press Enter. This will open the Command Prompt. macOS: Press Cmd + Space to open Spotlight Search. Type Terminal and press Enter. This will open the Terminal application. Linux: Press Ctrl + Alt + T to open the Terminal.
For better command line tools you can install both Microsoft PowerShell (not windows powershell) and Microsoft Terminal. These two tools are updates and are better than the built in ones.
run the following in the terminal:
python –version
- Windows - python, py commands should work
- Linux/Mac python or python3 should work
py –version python –version python3 –version
I use python version 3.
if you didn’t get Python 3 (pref 3.8 or higher) for any you will need to download a new version. Current version as I write this is 3.12.
Installing Python
Installing Python is straightforward. Here are the steps to install Python on different operating systems:
Windows:
- Visit the official Python website: Python.org.
- Navigate to the Downloads section.
- Choose the version of Python you want to install (e.g., Python 3.12.3).
- Select the appropriate installer for your operating system (Windows).
- Double-click the installer file to launch the setup wizard.
- In the setup window, check the Add Python 3.8 to PATH option.
- Click Install Now to begin the installation. It will take a few minutes to complete.
macOS:
- Visit the official Python website: Python.org.
- Navigate to the Downloads section.
- Choose the version of Python you want to install (e.g., Python 3.12.3).
- Download the macOS installer.
- Double-click the installer file to start the installation process.
- Follow the on-screen instructions to complete the installation.
Linux:
-
Most Linux distributions come with Python pre-installed. However, you can install a specific version using package managers like apt, yum, or pip.
-
Open a terminal and run the following command to check if Python is already installed:
- python3 –version
-
If not installed, use the package manager to install Python 3 (e.g., sudo apt install python3).
Remember to choose the appropriate version of Python based on your needs and system requirements. Happy coding! 🐍🚀
For more detailed instructions, you can refer to the official Python installation guides:
Dive Into Python Python Tutorial Real Python How-To Geek 1 2 3 4 5 Source: Conversation with Bing, 2024-04-29
(1) Download Python | Python.org. https://www.python.org/downloads/.
(2) How to Install and Run Python: A Beginner’s Guide - Dive Into Python. https://diveintopython.org/learn/install.
(3) Install Python on Windows, macOS, and Linux - Python Tutorial. https://www.pythontutorial.net/getting-started/install-python/.
(4) Python 3 Installation & Setup Guide – Real Python. https://realpython.com/installing-python/.
(5) How to Install Python on Windows - How-To Geek. https://www.howtogeek.com/197947/how-to-install-python-on-windows/.
(6) undefined. https://www.python.org/.
(7) Getty Images. https://www.gettyimages.com/detail/news-photo/in-this-photo-illustration-a-python-logo-seen-displayed-on-news-photo/1986209604.
Do you already have python? I have used cmd on windows, you can use whatever terminal you know how to open. A shortcut on windows is to use explorer to go to the folder you want and type cmd in the bar above.
Windows - python, py commands should work Linux/Mac python or python3 should work
run the following:
python –version if the response is not python 3 or higher then i recommend you check the py command or the python3 command
py –version or python3 –version if still not you will need to download a newer version. I tend to like to get it directly from the vendor which would be Python website and look at their install instructions if you still have problems.
Once you know how to get python 3 (or newer) we can continue. NOTE from now on I’ll just refer to it as python but please use the command that works best for you.
Where do I put this code I like to have a “dev” or “source” folder under my home folder. Then I create folders under that for each of my projects. You can group by language or if you have specific work requirements then follow those.
Under the Home directory would be your source folder. Under that would be your project folder which can be anything you choose. We use my_project for this example. Under my_project we would create the venv/. In here we will create .git/ and .gitignore. If using an IDE like VSCode we would open on this folder and have the venv automatically recognized. A terminal and text editor are sufficient, though I find beginners may prefer the help like code completion etc.
Creating the venv/ folder We don’t want to clutter the python global environment, nor do we want each project to use the global versions as changes to one projects dependencies may break another. We create a project level virtual environment to give us flexibility.
python -m venv venv the first venv after the -m is the python module, the second is the folder name we chose.
we activate it in windows with
venv\Scripts\activate Linux and Mac will use
source venv/bin/activate After it is activated then install with pip will place those files safely in the virtual environment (venv).