Unbreaking Python Through Virtual Environments

  • The ability to change the global Python version on a per-user basis.
  • Provide support for per-project Python versions.
  • Allow override of the Python version with an environment variable.
  • Search command for multiple Python versions at a time.
  1. Use virtualenv-1.9 or greater.
  2. Advise against pip 1.3.

Step 1 Install virtualenv

pip install virtualenv

Step 2 Setup a New Environement

virtualenv <dir>
$ virtualenv python-env-examples 
Using base prefix '/Users/adron/.pyenv/versions/3.7.3'
New python executable in /Users/adron/Codez/python-env-examples/bin/python3.7
Also creating executable in /Users/adron/Codez/python-env-examples/bin/python
Installing setuptools, pip, wheel...
done.
  • /python-env-examples/lib and /python-env-examples/include now exist and contain libs for the environment, with /python-env-examples/lib/pythonX.X/site-packages being the location that will now receive any packages that are installed to the environment.
  • a bin directory is created for executables to live including a new python executable. We can even use this directory's path to run a script by issuing /python-env-examples/bin/python or use the specific environment for a pip install. Check the specific versions in that directory with python --version and pip -V to determine what version is setup in that particular environment. This also can be used to determine the difference between the system Python that is setup versus the specific environment.

Step 3 Activate The Environment

> ls
activate activate.ps1 easy_install pip3 python-config wheel
activate.csh activate.xsh easy_install-3.7 pip3.7 python3
activate.fish activate_this.py pip python python3.7
source ./activate
deactivate

--

--

--

Software dev, data, heavy metal, transit, economics, freethought, atheism, cycling, livability, beautiful things & adrenaline junkie.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Support the Entire HTML Spec with Macros

An open letter to junior developers starting their first role (with gifs!)

Feeding a monster — Solving a problem with bulk data importing

Benefits of an Online FTP Server

Implementing an Idiomatic Service DSL

Collect Microsoft Teams activity logs in Azure Sentinel

5.2 Day 1: The Castle on the Hill

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adron Hall

Adron Hall

Software dev, data, heavy metal, transit, economics, freethought, atheism, cycling, livability, beautiful things & adrenaline junkie.

More from Medium

Python Lesson : Tuples in Python

Writing a shell in python

Powershell Scripting Guide to Python

Python pushed with Git-hub!