yahia-soliman / alx-higher_level_programming

Learning OOP & TDD with Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

programming with Python

This is part of my journey at ALX, it is the second sprint -aka semister (3 months)- in this sprint we will learn Python.

Before starting

its important to have an isolated environment to be specific to the work related to alx because the project at ALX requires using Python3.8.5, and the version of Python in my machine is the latest version and will be the latest always; because of the programs depinding on it.

Installing and isolating a Python release

To make this possible we can simply install the package related to the version we need usnig the package manager in our linux distro (in my case it is pacman; I use Arch btw ^_^), but I prefer to have this setup isolated from the global PATH where every thing is connected together, hence we will need it only for specific projects.

  1. Get the vesion you want from python/downloads
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
  1. Unzip the tar.xz file you got
tar -xf <filename.tar.zx> -C <path/to/extarct>

Now have the source code of the release we downloaded at the path/to/extract we gave above Note that this directory will be of our virtual environment directories Here is how it will look like at the end:

πŸ“‚ ~/.venv         ~> imagine this as the root of our environments
β”‚
β”œβ”€β”€ πŸ“ rel         ~> releases we will install for the environs
β”‚   β”œβ”€β”€ πŸ“‚ src     ~> the source code we downloaded and extracted
β”‚   β”œβ”€β”€ πŸ“‚ bin     ~> these 3 are stantard for the installed binary 
β”‚   β”œβ”€β”€ πŸ“‚ lib     ~~ you can use any names you prefere for any dir
β”‚   └── πŸ“‚ lib64   ~~ instead for these 3 standard ones
β”‚
β”œβ”€β”€ πŸ‡» vert-env-1  ~> the virtual environments we will make later
β”œβ”€β”€ πŸ‡» vert-env-2
└── πŸ‡» ....

  1. Use the configure script to specify where we want to compile the source
./configure --exec-prefix=$HOME/.venv/rel/
  1. Finally compile the soucre and make the release's executable binaries
make altinstall clean

Making the virtual Python environment

Now we have the specific Python release we want, and it is isolated from the PATH directorys meaning that if I typed python in the terminal it will execute the version that is inside the PATH directorys and this is what I want; to avoid any conflict with the project specific Python and the global Python release used by any program in the system.

to make a virtual Python environmet see python/venv:

<path/to/python/executable> -m venv </path/to/new-virt-evn/directory>

For example: to make a Python3.8 vertual environment and its name is "ALX":

$HOME/.venv/rel/bin/python3.8 -m venv $HOME/.venv/ALX

To activate ALX we need to source a shell-script that will do the magic

source $HOME/.venv/ALX/bin/activate

Now the current shell session and any child proccess from it will act as if the python version we working on is 3.8.5 instead of 3.11 in additon we can use pip to install any Python library or package we want and it will be execlusve for the ALX environment

In our example to exit the ALX environment just type:

deactivate

About

Learning OOP & TDD with Python


Languages

Language:Python 84.0%Language:JavaScript 7.4%Language:C 6.3%Language:Shell 1.6%Language:HTML 0.4%Language:Makefile 0.2%