How to Install Python 3 PIP and Virtualenv for a Data Scientist Environment
ArticleSeptember 13, 2024

How to Install Python 3 PIP and Virtualenv for a Data Scientist Environment

CN
@Zakariae BEN ALLALCreated on Fri Sep 13 2024
Python 3 guide to installation

Thank you for visiting this tutorial. I’ve personally crafted every aspect of this blog, and I’m delighted to share with you what I’ve learned about AI. 🌟

In this section, I’ll guide you through the best practices for installing and setting up a Python development environment. Installing Python can sometimes be tricky, especially when deciding between Python 2.7 and Python 3+. I’ll also explain how virtual environments (venv) work and demystify the meaning of PEP (Python Enhancement Proposal). πŸπŸ’»

So, sit back, relax β˜•, and let’s dive in !

1. Getting Started with Python

To start our journey, I’ve signed up for several Python courses designed with data scientists in mind. πŸ“š These courses cover everything from the fundamentals of Python programming to advanced topics such as data manipulation, analysis, and developing machine learning models.

By completing these courses, we’ll build a strong Python foundation, empowering us to tackle sophisticated projects like constructing LLMs confidently. πŸš€

We will use Jupyter and VSCode, and you can find all the source code on my GitHub repository. πŸ’»

2. Python introduction

πŸ€” What is the version of Python?

πŸ’‘ We have two options: Python 2.7 and Python 3+. Spoiler alert: Python 2.7 is not compatible with the latest Python versions (specifically version 3 and higher), and Python 3+ does not maintain backward compatibility with older versions. Therefore, for our purposes, we will exclusively use Python version 3 or higher throughout this blog.

πŸ€” What is PEP?

πŸ’‘ PEP stands for Python Enhancement Proposal. It’s a document that provides information for Python developers or explains new features for Python. PEPs offer technical specifications for Python, making them easy to understand and implement in coding practices.

πŸ€” What is pip?

πŸ’‘ pip is the package installer for Python. It allows you to easily install and manage Python packages from the Python Package Index (PyPI). Whether you’re adding libraries for data analysis, web development frameworks, or tools for machine learning, pip simplifies the process by handling dependencies and ensuring packages are installed in your Python environment. It’s an essential tool for Python developers to extend the functionality of their projects efficiently.

πŸ€” What is venv?

πŸ’‘ venv is a Python module used to create virtual environments. Each environment can independently manage its own Python package versions within its directory. It’s a straightforward tool that ensures clean and isolated environments for different projects.

Easy peasy lemon squeezy!Β πŸ‹

3. Installation

Now, let’s dive into setting up our Python environment β€”Β it’s code time!Β πŸ˜ŠπŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

Linux

For the Linux environment, please note that the code below has been verified on Ubuntu. Make sure to verify your operating system version and adapt the commands accordingly ✨.

$ python3 --version
Python <strong>3.11.6</strong> #version 3.X.Y  (3.11.6 on my linux machine)
JavaScript
  1. Check Python local version (if installed)

If theΒ PythonΒ command is not found, you’ll need to install Python 🐍.

  1. Installation Python 3 or higher
<code>$ sudo apt-get update
$ sudo apt-get install python3
</code>
JavaScript

After updating and installingΒ Python 3, now you need to check if Python 3 has been installed correctly βœ…

<code>$ python3 --version

Python 3.11.6 # version 3.X.Y  (3.11.6 on my linux machine)

</code>
JavaScript

If the version of Python is displayed, it means Python is installed and available in your terminal context.

Happy coding !Β Let’s move on to the next step. πŸŽ‰

  1. Use Python 3 and print β€œHello, World!” :
<code>$ python3

Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> print('Hello, World!') # print hello world on your terminal
Hello, World!
</code>
JavaScript

Congratulations on your first β€œHello, World!” in Python! πŸŽ‰πŸ Keep up the great work!

  1. Install virtualenv (Recommanded)

Firstly, you should install pip πŸ› οΈ, This command will update your package index and then install pip for Python 3 on your system.

<code>$ sudo apt update<br>$ sudo apt install python3-pip<br></code>
JavaScript

Check if pip installed correctly by running the following command: πŸ’»πŸ”

<code>$ pip3 --version<br>pip 24.0 from $HOME/.local/lib/python3.11/site-packages/pip (python 3.11)<br></code>
JavaScript

Cool 😎! To install and use virtualenv in Python, you just need two command lines. Here’s how to update and initialize a virtual environment (venv):

These commands first install virtualenv using pip and then initialize a virtual environment named .venv in the current directory.

<code>python3 -m pip install --user virtualenv<br>python3 -m venv .venv # init .venv on current directory<br></code>
JavaScript

Wohooo, congratulations! πŸŽ‰ You’re now on the latest step.

You’ve installed Python 3 and initialized a virtual environment (venv). Just so you know, venv creates all necessary data and imports Python libraries into the current directory.

Let’s take a look at the .venv directory πŸ“.

$ tree .venv
.venv
β”œβ”€β”€ bin
β”‚   β”œβ”€β”€ activate
β”‚   β”œβ”€β”€ activate.csh
β”‚   β”œβ”€β”€ activate.fish
β”‚   β”œβ”€β”€ Activate.ps1
β”‚   β”œβ”€β”€ pip
β”‚   β”œβ”€β”€ pip3
β”‚   β”œβ”€β”€ pip3.11
β”‚   β”œβ”€β”€ python -> python3
β”‚   β”œβ”€β”€ python3 -> /usr/bin/python3
β”‚   └── python3.11 -> python3
β”œβ”€β”€ include
... More files
JavaScript

πŸ—οΈ Windows πŸ—οΈ

πŸ—οΈ MAC OS πŸ—οΈ

Conslusion

Now that Python is installed, it’s time to kick off your project and dive into coding with Python 3! πŸš€

This language is beloved by many for its straightforward syntax and wide range of applications. Whether you’re just starting out or you’re a seasoned pro, Python 3 is perfect for everything from building web apps and automating tasks to crunching data and creating machine learning models.

So, roll up your sleeves, fire up your IDE, and let’s bring your ideas to life with Python! πŸ’»πŸ

Thank You for Reading this Blog and See You Soon! πŸ™ πŸ‘‹

Let's connect πŸš€

Share this article

Stay Ahead of the Curve

Join our community of innovators. Get the latest AI insights, tutorials, and future-tech updates delivered directly to your inbox.

By subscribing you accept our Terms and Privacy Policy.