Unbreaking Python Through Virtual Environments

> Since you’re using pyenv, the version of pip you use should always be the one associated with the current version of Python, which won’t be the case when you later switch versions.

> People who aren’t clear on what’s going on will likely copy the code you included verbatim, so instead of aliasing the version of pip referenced in the pyenv path, it’s going to always point at the brew installed version.

> You really should use virtualenv for pretty much everything and try to avoid ever installing libraries into your global Python environment. If you need tools accessible outside a virtualenv, check out pipx.

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.

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

--

--

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