Why I always use virtualenv to try out new libraries.

One thing that I always do with virtualenv is to install new Python libraries in a new virtualenv before I install them into the one I'm currently working with.

Here's how I do this:

$ virtualenv venv
New python executable in /Users/petko/work/post/venv/bin/python
Installing setuptools, pip, wheel...done.

$ . ./venv/bin/activate
(venv) 

$ pip install cryptography
... lengthy install log ...

$ pip install pipdeptree # Awesome tool, more in a bit.

$ pipdeptree
Warning!!! Possibly conflicting dependencies found:
* cryptography==1.3.2
 - setuptools [required: >=11.3, installed: <unknown>]
------------------------------------------------------------------------
wheel==0.26.0
wsgiref==0.1.2
cryptography==1.3.2
  - setuptools [required: >=11.3]
  - enum34 [installed: 1.1.6]
  - ipaddress [installed: 1.0.16]
  - pyasn1 [required: >=0.1.8, installed: 0.1.9]
  - six [required: >=1.4.1, installed: 1.10.0]
  - idna [required: >=2.0, installed: 2.1]
  - cffi [required: >=1.4.1, installed: 1.6.0]
    - pycparser [installed: 2.14]
(venv) 

That's it! Now I can experiment with a new library without worrying that it'll pollute my work virtualenv. Another thing that I do is using pipdeptree to see the dependencies that a new library will bring with it. If a library brings in too many dependencies, I'll be thinking twice about my need to use it, or I'll look for alternatives.

social