Python environments
Global
If you have not read the last post about Python we strongly recommend you have a read, just for the introduction of why Python versions play a big role on the importance of environments.
In that last post, we also mentioned that installing Python directly from the main page (python.org) is not standard practice anymore. In order to have python in your computer, we recommend using a distribution software manager.
Distribution software manager
A distribution software manager (or language distribution) is a pre-packaged collection of a programming language, its core tools, and Virtualpopular libraries — all bundled together to make setup and environment management easier.
Instead of installing everything separately (Python, data science libraries, version managers, etc.), a distribution gives you a ready-to-use ecosystem that’s designed for a specific purpose — like data analysis, machine learning, or scientific computing.
If we follow our previous analogy of seeing environments as a "tool box" you can think of it like buying a starter toolkit: instead of just getting the screwdriver (the programming language), you get the full toolbox — with wrenches, pliers, and screws already organized.
NowFor thatPython there are different ways you can create an environment. If you already understand what an environment is, skip this and go directly on how to set them up:
- Create an environment with Anaconda
- Create an environment with Miniconda
- Create an environment with venv
All of the above links will also explain how Python can be installed alongside the distribution software manager.
From now on, we will assume you have installed Python,Python. If we mentionedused one of the distribution software manager is worth mentioning that it comes with certain pre-installed basic libraries.
But what happens when you want to use Python for a specific task and need to install additional packages? For this, Python has enabled pip, a recursive acronym for "Pip Installs Packages" or "Pip Installs Python", as its package manager to automate installation, update, and package removal.
conda (the command to call the Anaconda distribution from your command line) is also a package manager you can use to install libraries, but is good form to use one OR the other when using environments.
However, if you are not using a distribution software, and just have a main installation of Python for the whole system, installing new packages directly into the download of Python can have difficult consequences.consequences, Thisnot Pythonto we just installed ismention the Globalupgrade environment. We mentioned that Python is an open-source interpreted programming language that goes through constant updates. For this reason, newer libraries developed on differentof Python versions oftenbecomes conflictreally with libraries without the same updates, and error messages start to pop up.annoying.
Dmitriy Zub, Dec 22, 2021. Python Virtual Environments tutorial using Virtualenv and Poetry. Place of publication: SerpApi. Available here.
This image is a beautiful, chaotic example of what happens to your global environment when we do not have order in the different paths and versions of new packages.
The old way of installing Python from the main web page to the entire system we just installed is the Global environment. We mentioned that Python is an open-source interpreted programming language that goes through constant updates. For this reason, newer libraries developed on different Python versions often conflict with libraries without the same updates, and error messages start to pop up.
To avoid this, a good practice when using Python is to use virtual environments. This environment allows for isolating package dependencies so they do not clash.
For example, you may have two projects, one for computer vision and another for Natural Language Processing (NLP). Both of them use similar libraries but in different versions of Python. We can not install both versions system-wide, but we can create isolated environments for each project.
These environments are called containers because they do not interact with each other. However, this is only for the system. The folders and files in your storage are all available for all the environments. This means that if you remove, add, or change a folder when you are working inside an environment, that change is permanent and will apply to all environments
There
Diference arebetween differentenvironments waysand to build Python environments:
IMPORTANT:
folders
We Pleasemention in this last note that allthese environments we are creating for different Python versions will not interact with each other when we are installing different libraries and different versions of libraries.
When working with Python, it helps to understand the stepsdifference mentionedbetween system memory (RAM) and storage memory (like your hard drive, SSD, or SD card), and how they relate to your Python environments.
Storage Memory (Hard Drives, SSDs, SD Cards)
This is your permanent memory — where your files, folders, programs, and Python environments are stored.
Everything you install (like Python itself or a library) is saved here until you delete it.
Examples:
-
Your project folders (my_project/)
-
Python installations (C:\Python311\ or /usr/local/bin/python3)
-
Virtual environments (env/, .venv/, conda_envs/)
Each Python environment is just a folder stored on thisyour pagehard drive that contains:
-
A copy (or link) to a specific Python version
-
Its own site-packages folder with installed libraries
-
Some configuration files
That’s how different environments can have different libraries and versions without interfering with each other — they’re stored in separate folders on disk.
System Memory (RAM)
RAM is your temporary working memory — what your computer uses while programs are recommendedrunning.
fromWhen originalyou sources;run tryyour to follow them as faithfully as possible. If,code in anyVS step,Code, somethingPython doesloads notthe worknecessary asfiles itand should, contact a technician first before following any other instructions that need you to move things directlydata from your terminal.disk
into RAM. Once Pythonyou close your program or restart your computer, RAM is cleared, but your files and environments (venv):
remain
We Pleasemention in this last note that allthese environments we are creating for different Python versions will not interact with each other when we are installing different libraries and different versions of libraries.
When working with Python, it helps to understand the stepsdifference mentionedbetween system memory (RAM) and storage memory (like your hard drive, SSD, or SD card), and how they relate to your Python environments.
Storage Memory (Hard Drives, SSDs, SD Cards)
This is your permanent memory — where your files, folders, programs, and Python environments are stored. Everything you install (like Python itself or a library) is saved here until you delete it.
Examples:
-
Your project folders (my_project/)
-
Python installations (C:\Python311\ or /usr/local/bin/python3)
-
Virtual environments (env/, .venv/, conda_envs/)
Each Python environment is just a folder stored on thisyour pagehard drive that contains:
-
A copy (or link) to a specific Python version
-
Its own site-packages folder with installed libraries
-
Some configuration files
That’s how different environments can have different libraries and versions without interfering with each other — they’re stored in separate folders on disk.
System Memory (RAM)
RAM is your temporary working memory — what your computer uses while programs are recommendedrunning.
When originalyou sources;run tryyour to follow them as faithfully as possible. If,code in anyVS step,Code, somethingPython doesloads notthe worknecessary asfiles itand should, contact a technician first before following any other instructions that need you to move things directlydata from your terminal.disk
venvFor this type of environment,on the disk.
Each project has its own environment folder, so when you install or uninstall a library in one, it doesn’t affect the other.
That’s because the installation only requirementchanges forthe files inside that specific environment’s folder on your computerdisk — it doesn’t touch the global system files.
This is what we call environment isolation.
When Changes Become “Global”
The isolation only applies to havewhat’s inside the environment — things like installed libraries or Python versions.
However, if you modify or delete files in your project folder or environment directory directly (for example, from VS Code’s file explorer), that’s a versionglobal ofchange Pythonto installedyour onstorage.
Examples:
venv-
Installing a
Pythonpackagemodule that supports lightweight virtual environments.For this type of environment, you need to be familiar with how the terminal works, how you can move from one folder to another, and the Python versions you have installed. If you are unfamiliar with these requirements, please refer to the How to use Anaconda section.From Python 3.3 onwards,venvshould be included in the commands available. To createinside a virtual environmentwith→this,affectspleaseonlyopenthat environment -
Deleting a script file or folder from VS Code → permanently removes it from your
terminal:hard drive (affects everything using that file)NOTE:So,
Ifenvironmentyouchangeshave(vianotpipyetorinstalledconda)Pythonare isolated, but file changes (via the file system) are always global, because they modify the actual storage on yourcomputer, please refer to the Installing Python section of the wiki.disk.macOSToAction enterType theScope terminal,youcansearchit directly from the Launchpad or application folder. TypeCommand+Space barand type terminal forInstalling a shortcut. First, we must ensure you arelibrary inthe folder where you want to save the environment. When you open the terminal, you should see only your user name:For this example, I am going to access my Documents folder. You can access whatever folder you wish to save your environment on.WHY IS THIS IMPORTANT?If you savea virtual environmentEnvironment change Isolated Switching Python versions with thepyenvsameornamecondaEnvironment change Isolated Editing/deleting files in theVSsameCodefolder,File thesystemterminalchangewillGlobal interpret(affectsitstorage)asRunning code or loading data Uses system memory (RAM) Temporary Things that might interest you
wantaftertoreadingrewrite it, and you will lose the information from the previous one. Before creating new environments, make sure that the name and folder you choose differ from previous ones.
python -m venv [name of the environment]
Inside of the brackets, you can change it to whatever name you want. Just make sure that the name of the environment is something easy to remember, or write it down somewhere. The name should also follow the terminal rules: if you are going to name something with more than one word, you need to hyphenate the words with an underscore (_).
The way you activate it is while inside the folder where you created the environment, call source [name of the environment]/bin/activate. The name in front of the dollar sign should change to the name of the environment you are currently in.
Example:
WINDOWS OS
For the Windows OS you also need to have previously installed Python.
If you installed Python by downloading the installer directly from the Python page, you might need to add the path to the environment variables of your computer. Please see the section on how to do that in the "Add path to environment" section. If you are not familiar with the path and what it means to add it to the environment variables, please continue with the next steps.
If you have Python already in your Path variables, you can just use the same arguments as the macOS instructions.
Example:python -m venv example_environment
Please note that the same rules apply to Windows, so make sure to name the environment something unique and easy to remember, and also select the correct folder for your environment.
Conda environments
Another way to create environments in Python is to use the Anaconda distribution. For this, we have two options: we can download Anaconda from the official distribution or a more light version of Anaconda called Miniconda.
These two versions are from the same distribution and are widely used for data science and scientific computing. The main difference between the two is the size of the installation. Anaconda requires at least 3 GB of free disk space, while Miniconda only requires 400 MB (Something you need to take into consideration if you do not have enough space available on your computer). Anaconda comes with a large array of pre-installed packages and a very user-friendly graphical interface that can favor those who are not very familiar with the use of the terminal or command line prompts. Miniconda only includes the `conda` function and Python in its installation.
If you go for the Anaconda version:
macOS
If you go to the official Anaconda page (https://www.anaconda.com/download#downloads), you will see the Download button for your OS. If you are using macOS, it is also important to know if your hardware settings are an Intel chip or an M1/M2/M3 chip.
You can check this by going to the Apple at the top left corner of your screen and clicking on About this Mac.
This should prompt a Window that will say the chip your computer has:
Go back to the Downloads page on Anaconda and choose the right setting for your computer.
You can also click on `More info` to see all the different settings on your computer.
Once the package is done loading, you can choose the predetermined installation and click install. If your terminal was opened, please relaunch it, you will now be able to see the pre fix in your user name as (base). Which means that you are in the base or root environment. We explain this later on.
It goes from:
To look something like this:
For Windows users:
For Windows, there is only one universal installer, so it does not matter the version of Windows that you are using. It is only important to know that it is only available for the 64-bit version. If your computer is a 32-bit, please look into the Anaconda archive (https://docs.anaconda.com/free/anaconda/install/old-os/).
Follow the installation process. Same as with the Python installation, this installer is going to ask you if you want to add this software to your path variables. If you are not sure or do not understand fully what path does, do not activate this function. We can change it later on if you need it.
If you do not want to add Conda to your path variables, you can use the command prompt directly from the Anaconda Navigator. Otherwise, all the other Windows terminals will not have the `conda` prompt.
Installing Miniconda
Please be mindful that Miniconda has no user interface and only offers the `conda` prompt and Python. It also requires general knowledge of how the terminal works.
Graphical installer:
macOS
You must download the Miniconda installer from the official page (https://docs.anaconda.com/free/miniconda/). From here, you can choose the Intel or the M1/2/3 chip version and the bash or pkg versions. We strongly recommend using the bash version since the pkg may skip the "Destination select" process, failing the installation.
bash
Once you download the document, locate where it is stored (it is most likely in the Downloads folder).Go to a new terminal in your computer (Command+Space bartype terminal +Enter)Go into the folder where you have the bash file stored (Ej.cd Downloads); you can verify it is there by runningls.This is an optional step, but we recommend verifying the download to ensure everything will run correctly. In your terminal runshasum -a 256 filenamereplacingfilenamewith the downloaded file name. If it does not raise any error, follow the next step.Runbash <conda-installer-name>-latest-MacOSX-x86_64.sh. Replace the<conda-installer-name>with the downloaded file's name.Once the process is finished, please close and reopen your terminal (Command+qto close/reboot the program completely. You can see if this was successful by clickingCommand+tab. It should show you all the applications you have opened. Make sure that the terminal does not show there).To verify the installation, open a terminal window and runconda list. If you installed everything correctly, a list of all the installed packages should appear.
Windows
For Windows, you can just download the .exe file and run it. In case you want to install it directly from the command line, you can run the following code:
If your computer is not 64-bit, you can look into miniconda archive installs. Just keep in mind that older versions are not compatible with newer versions of Python, and will limit the amount of new libraries you can use.
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
The curl command allows the terminal to exchange data directly from another server, in this case, it is making an HTTP request, just like a web browser. If the request fails, make sure that your internet connection is stable. Once the download is complete, type:
start /wait "" miniconda.exe /S
This will start the installation process. Afterward, you can run del miniconda.exe to delete the executable file.
After installing, close the terminal and open the "Anaconda Prompt (miniconda3)" to use miniconda.
