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

CN
@Zakariae BEN ALLALCreated on Fri Sep 13 2024
How to Install Python 3 PIP and Virtualenv for a Data Scientist Environment
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 ๐Ÿš€

Newsletter

Your Weekly AI Blog Post

Subscribe to our newsletter.

Sign up for the AI Developer Code newsletter to receive the latest insights, tutorials, and updates in the world of AI development.

By subscription you accept Terms and Conditions and Privacy Policy.

Weekly articles
Join our community of AI and receive weekly update. Sign up today to start receiving your AI Developer Code newsletter!
No spam
AI Developer Code newsletter offers valuable content designed to help you stay ahead in this fast-evolving field.