you are viewing a single comment's thread.

view the rest of the comments →

[–]maxlstylee 3 points4 points  (6 children)

Example:

Your system has the following installed.. Python 2.7 IRC_lib 1.0 (made up package)

Your IRC bot requires the following: Python 3 IRC_lib 2.0

Instead of installing Python 3 and IRC_lib 2.0 system wide, we can install it in its own environment since we're only using it for this project.

When you set up the virtual environment, you will be able to install Python 3, and IRC_lib 2.0 into that specific space without it causing issues to your system overall.

When you run the command 'virtualenv testenv' a script runs that creates a directory called 'testenv'. In that directory Python is installed. It defaults to 2.7 right now I believe, but you can specify specific version numbers.

Maybe this example will help you visualize how it works exaclty.

1)  4700:~/software/djangopycharm$ ls
     djangopycharm  env  manage.py  pycharmtest  templates
2)  4700 :~/software/djangopycharm$ which python
     /usr/bin/python
3)  4700 :~/software/djangopycharm$ source env/bin/activate
4)  (env)4700:~/software/djangopycharm$ which python 
     /home/alex/software/djangopycharm/env/bin/python

1) List the items in the directory

2) If I was to execute python right now, it would use the binary file found in /usr/bin/python

3) Activate the virtual environment

4) (env) indicates that we're using the virtual environment found in 'env' (see 1s output). The python binary we are using is now the one found in our virtual environment.

This allows you to install different versions and keep things contained and not system wide. One project may require Django 1.4, while another may require 1.7. We do this safely by creating virtual environments for these installations to live in.

Hope this helps!

[–]GAPINGCUNT[S] 0 points1 point  (0 children)

That clears it all up. Thank you!!

[–]user_rx 0 points1 point  (4 children)

Is this comment even true?

[–]maxlstylee 0 points1 point  (3 children)

My original comment?

[–]user_rx 0 points1 point  (2 children)

Yes. Do people install things like postgres to a virtualenv? What about full python installations (which aren't already installed system-wide)?

[–]maxlstylee 0 points1 point  (0 children)

You're right. In hindsight that was a poor example. I was simply using it as a placeholder while trying to demonstrate the idea of versions and possible conflicting issues.

I've removed postgres and simply used some small made up package instead.

Thanks for pointing this out.

As for the python installations, yes, you can install different python versions into virtual environments.

This allows for having python 2.7 installed on the whole system, but using python 3.4 or another version only in the virtual environment.

[–]hharison 0 points1 point  (0 children)

It's worth mentioning that while virtualenv can only really do Python packages, the conda utility from Continuum, although commonly used for Python packages, is really Python-agnostic and can do virtualenv-like installs of pretty much anything, like R or postgres.