Skip to content

C3n7ral051nt4g3ncy/python_virtual_environment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 

Repository files navigation

Python Virtual Environment (virtualenv)

Python 🐍 : Working in a Virtual Environment - macOS



What is a virtual environment?

An environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments. Meaning each tool you have will be isolated from each other and won't conflict with each other, as part of your OS (operating system).


Why set up a virtual environment?

You really don't have to be a python expert or developper to use a virtual environment, even though all Python Devs use a VE.

Think about this for a second, you do a lot of OSINT and you love using all the best python tools, the problem is that you have accumulated 30 or 40 tools that start to conflict with each other and you find yourself writing/starting an issue on Github because your awesome OSINT python tool is no longer operational.

One OSINT python tool may require of you to install Package A version 1.0 to your python lib (Library), another OSINT tool may require you to install Package A version 2.2, you install the requirements, and now you find that your tools stop working because of conflicting packages/python libs.
How about not having these issues by isolating the tools? 🧠


Image Above: Piotr PΕ‚oΕ„ski, https://mljar.com


Install a Virtual Environment using Venv

Requirements: First of all, you need to have Python installed: https://www.python.org/downloads/

Install Virtual Environment Command:

$ pip3 install virtualenv

Now let's create your project/tool folder: (mkdir stands for make directory)

$ mkdir project-Osint1
$ cd project-Osint1

cd command = change directory

Now that the the project-osint1 folder has been created, we have the luxury of choosing what python version we want to use in our virtual environment, and the virtual environment name. We can do this with the following command:

$ python3.9 -m venv myvenv

You can choose any python version and any name for your virtual environment,it is recommended to keep it short and simple.
Remember KISS:πŸ’‹Keep It Simple Stupid

Screen Shot 2022-08-24 at 14 29 21


Virtual Environment Activation

Everything needed has been created, but we need to activate the virtual environment in order for it to be useable. Activation command:

$ source myvenv/bin/activate

recap: source <your virtual environment name>/bin/activate

Let's check the Python Version: Command:

$ python --version

Let's check if everything is working correctly with one commmand:

$ pip list

This is an example I am using with the OSINT python tool called Twayback, after the pip list command, we can see all the libs and requirements that only concern Twayback, which is isolated from the rest of the libs on my system.


Screen Shot 2022-08-24 at 15 01 40

You may want to check the current version of virtualenv:


$ virtualenv --version

Another way of creating a Virtual Environment:

Make sure Pip is up to date:

$ python3 -m pip install --upgrade pip
$ pip3 install virtualenv
$ virtualenv venv 

(or the name you choose instead of venv)

$ source venv/bin/activate 

All is now ready for take-off πŸš€

Success! βœ…, your Virtual Environment has been created and is now activated, you can make the checks with the check commands given above, now install your python OSINT tools (git clone) , dependencies, requirements, libs etc.. You now have a much higher success rate with your OSINT Python tools and less chance of having to open an issue on Github , most of the issues that OSINT Analysts have is due to a lack of knowledge with Python, they keep adding dozens and dozens of tools on top of each other without isolating them, so the tools all conflict with each other, thus, creating a big messy salad of packages/libs all conflicting with one another.

Deactivation

To Deactivate and return to the default sys environment, the command is KISS, I bet you can guess what the command is right? πŸ€”

$ deactivate

To go back to your VENV (Virtual Environment)

  1. cd {directory}
  2. source {name of virtual environment}/bin/activate

Simple as that !

Enjoy using your Python 🐍 Virtual Environment !

About

Python: Working in a Virtual Environment (virtualenv)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published