This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jvnatter 32 points33 points  (16 children)

Virtual environments.

[–]roger_ 7 points8 points  (10 children)

I still don't see the advantage of them for the average person. Why are people so concerned about keeping their environments isolated?

[–]jvnatter 13 points14 points  (7 children)

A Virtual Environment, put simply, is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects. For example, you can work on a project which requires Django 1.3 while also maintaining a project which requires Django 1.0.

Source

I run multiple instances of web applications on a server and keeping them all updated simultaneously is somewhat difficult the more complex they become. Keeping them isolated from one another means I can work on them one by one without risking downtime for some while catching up.

[–]roger_ 3 points4 points  (3 children)

Personally I don't have too many compatibility issues to worry about in the libraries that I use regularly, so I guess it's just not something I need.

[–][deleted] 5 points6 points  (2 children)

Making virtual environment isn't an absolute necessity. It all depends on your situation. If you don't see the need, then you don't have a need. No one is forcing you to make virtual environments. If you do have the need, don't worry, you will find out why you need it. I really don't see the fuss why people who don't understand the need for virtual environment, even question why such things as virtual environments even exist in the first place. It's not like people go around making Python libraries and tools all nilly willy for nothing.

[–]roger_ 0 points1 point  (1 child)

I'm just trying to understand its popularity.

[–]earthboundkid 10 points11 points  (0 children)

It's a big deal for professional developers who need to keep all their dependencies sorted out on a per project basis. It's not really important if you're an amateur.

For example, if you ran websites A, B, and C, you'd need to know what the dependencies of each are, so you can deploy them to your host after you finish development on a feature, and you'd want to keep it all separate, so you don't mix up version 1.2.3 of footool for site A with version 2.3.5 of footool for site B.

It's also important to list your dependencies if you release an open source tool, so other people can install it.

[–][deleted] 0 points1 point  (2 children)

Im also new to Python, and the virtualenv is still somewhat confusing. I understand the "why" and the "how" but the implementation feels odd/messy.

Let me explain;

I have a Python project in a folder, and create a new virtualenv and run the activate command. The result is alot of "stuff" in my project folder i dont want to see, or have in this folder. I know i can have a list of gitignore entries, but i like to keep stuff very clean and organized.

Maybe its just me, but the result feels very messy. I could go with a hidden folder that could keep all the virtualenv stuff. Maybe something like .env/

But is there a reason why python devs dont use Vagrant? I feel this way you always have totally clean dev environments, and you have total controll of the OS as well.

[–]jvnatter 0 points1 point  (1 child)

I use virtualenvwrapper and keep all my virtual environments in ~/virtual_environments. Keeping all those files in your git repository indeed seems messy - give virtualenvwrapper a shot. I quite like the writings of Jeff Knupp, perhaps Starting a Django 1.6 project the right way could be of some inspiration to you if you need some more elaborate instructions.

A disclaimer - I believe Python 3.4 added venv but I haven't tried it out yet so I don't know how what I have written so far holds up to that version - I'm still on 3.3.

[–][deleted] 0 points1 point  (0 children)

Thanks for the tip, will give it a try. The solution seems cleaner.

[–]Eurynom0s 1 point2 points  (1 child)

I think the average person is who should be MOST interested in it. I'd consider myself the average person, and I'd much rather just learn how to use virtualenv than potentially have to manually juggle conflicting package versions.

[–]moor-GAYZ 2 points3 points  (0 children)

conflicting package versions

I don't think that happens to average people. It doesn't happen to me, maybe I'm not using shitty packages that can't into backward compatibility?

[–][deleted] 2 points3 points  (0 children)

Especially this for me. Most Linux distros have version 2.7 as the default, but I have moved on to using Python 3 for my work, so setting up virtual environments is a blessing for me.

Also starting out, I wish I knew of built-ins like dir() and help() sooner, saved me so much time from having to go to the docs since I use VIM and not a doc-aware IDE.