Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Isolating Dependencies With Virtual Environments

Give Feedback

00:00 In this part of the course, you’ll learn how to isolate your Python dependencies using so called virtual environments. Here is where you are right now in the course.

00:11 And this is what you are going to cover in the upcoming module in the course. You are going to learn about virtual environments, what they are, how they work, and what they are good for.

00:23 Next, you are going to learn how to create and activate a virtual environment on your system, after that, you’re going to learn how to install packages into a virtual environment; you’ll also learn how to deactivate virtual environments and how to completely delete them again.

00:39 And last, I am going to show you some tips in my personal workflow that I use to make working with virtual environments a little bit more efficient. Okay, ready? Let’s jump right in!

00:49 So we just learned that Python has a powerful package management system. What do we need that isolation for? The thing is that by default, pip installs all packages in a single shared environment, which means that if you need different versions of Python packages, there are going to be version conflicts.

01:08 Here is an example. Imagine you are working on two projects. Project #1 needs a specific version of Django, let’s say version 1.8, and it also needs a specific version of the Requests library, let’s say version 2.0.

01:22 Now, the other project, Project #2, needs a completely different version of Django, and it also needs a different version of Requests. Now if all of your packages need to be installed into the same shared environment, there are going to be version conflicts between these packages.

01:40 Another kind of version conflict you might face is that let’s say you are working on one project that actually needs Python 2.7 to run, and all of your new development happens in Python 3.

01:52 So, maybe you’re working on another project that actually requires Python 3.6 to run. How do you resolve these version conflicts? Virtual environments are really helpful tool that can help you with this problem, so a virtual environment allows you to isolate all of your Python dependencies by project, and this works for packages and also for different versions of the Python interpreter.

02:18 So you can think of these virtual environments as individual sandboxes for each project.

aravind on Sept. 17, 2019

Hi Dan, do you have any other courses where i can learn about pylint and pytest (writing and executing unit tests) and integrating these in a CI pipeline?

Dan Bader RP Team on Sept. 17, 2019

Hi aravind, check out these three courses:

I also recommend that you take a look at this learning path:

realpython.com/learning-paths/test-your-python-apps

aravind on Sept. 18, 2019

Hi Dan, thanks. I will go through the links.

Meanwhile, do you have a video or upcoming course on “TOX”? I think its tox.readthedocs.io/en/latest/. * Tox vs. PyTest * When to use which * Pros/Cons of each * Sample test cases using Tox

Dan Bader RP Team on Sept. 18, 2019

Yep, we do have a Python testing tutorial on tox. pytest and tox do two completely different things, so it’s not really a “pytest vs tox” question IMO. But you’ll hear all about it in the tutorial I linked above :)

aravind on Sept. 19, 2019

Fantastic, Dan - really loving the courses on this website and also the support in the comments/forums - keep up the great work & looking forward to purchasing further courses!

Become a Member to join the conversation.