Python Virtual Environments, what are they and how to make one?

Better Everything
3 min readFeb 16, 2023

A virtual environment is an isolated environment which you can use to group the dependencies of a Python project.

Dependencies are pieces of software that need to be installed for a script to run without errors. The script depends on them. The dependencies of a Python file include Python itself and packages, like pandas and matplotlib, that you import and use in the script.

The different projects you make might require different packages or different versions of packages. In that case virtual enviroments can be a solution for you.

Virtual environments are isolated environments in which you can install dependencies for a Python project.
Virtual environments are isolated environments in which you can install dependencies for a Python project. Image by catalyststuff on Freepik

By using virtual environments you can:

  • keep an overview of what the actual dependencies of a project are which is nice when you want to copy the project
  • have different versions of a package on a computer.
    Code that is written and tested with an older version of a package does not always work with newer versions. So just updating a package to the newest version might cause problems for old projects.
    By being able to use different versions you can keep your old code working with the older version and make a new project with a newer version at the same time.

How to make a virtual environment for Python?

--

--

Better Everything

📖 My E-Books: amazon.com/author/better-everything ✅Programming, Data & Business ✅Automation & Optimization ✅Knowledge & Inspiration