TL;DR
Quick walkthrough on how to install Virtualenv on Mac OS two different ways. This is an easy way to manage Python and it's dependencies in your projects.
592 votes, 51 comments. 139k members in the MacOS community. Reddit's Home to Apple's Latest Operating System! Mac OS X's Spaces (part of Mission Control since OS X 10.7 'Lion') is a feature that allows you to spread your programs across up to 16 separate desktop areas. These spaces will help you to organize your activities, since they provide you with far more 'space' to work with than is available on your physical display(s). Mac OS comes with a version of Python pre installed already usually 2.7.x or something of the like. As Python2.7 is no longer supported by the maintainers of Python so going forward you are going to want to use some sort of Python3.
Install Virtualenv with pipx
Install Virtualenv with pip
I just want to watch the video!
Why Virtualenv?
When working on multiple Python projects they will not always be running on the same version of Python. So a better way to manage the version of Python you are using is by creating a Virtual Environment.
Virtual Environments are isolated from the rest of your computer and are only responsible for each individual project's Python version and the dependencies of your project.
Virtualenv is one of several tools that solves this problem.
Mac OS Python vs. Python3
Mac OS comes with a version of Python pre installed already usually 2.7.x or something of the like.
As Python2.7 is no longer supported by the maintainers of Python so going forward you are going to want to use some sort of Python3.
You can download the latest version of Python here.
You can find out which version you have by running the following command in your terminal.
When downloading Python3 this is distinguished by calling it just that, Python3.
Install Virtualenv on Mac OS
There are multiple ways to install Virtualenv so I will show a couple different ones.
How To Install Virtualenv with pipx
If you already have a Python 3.5+ interpreter the best is to use pipx to install virtualenv into an isolated environment. This has the added benefit that later you'll be able to upgrade virtualenv without affecting other parts of the system.
Virtualenv DocumentationHow To Install Virtualenv with pip
Alternatively you can install it within the global Python interpreter itself (perhaps as a user package via the –user flag). Be cautious if you are using a python install that is managed by your operating system or another package manager. pip might not coordinate with those tools, and may leave your system in an inconsistent state.
Virtualenv DocumentationMake sure when using this command you are specifying python3 and not just python
Virtualenv In Action
1. Create a new project folder
2. Setup virtual environment
Room 51 Mac Os Download
3. Activate virtual environment
4. Check which version of Python you have running
It should be python3.7 or the like.
5. Deactivate the virtual environment
6. Check which version of Python you are running again. It should now say the old python2.7 version.
Summary
That's it! That is a couple ways i have seen how to install Virtualenv on Mac OS.
I hope you found this walkthrough helpful!
How To Install Virtualenv on MAC OS Video Walkthrough
Room 51 Mac Os Update
You can find the video for this and other Web Development tutorials at our Youtube Channel DeadbearCode!