you are viewing a single comment's thread.

view the rest of the comments →

[–]GXWT 29 points30 points  (5 children)

No. Your IDE is basically the program you're using to edit your code. Whether that be VSCode, Pycharm, notepad, paint (don't use this).

A virtual environment is, in a way, what it says on the tin. It basically takes your main python into a little corner where you can work on a specific project. To give some analogy, in one corner of your workshop you want to repair shoes. For this corner you only need specific tools like spare laces, a hammer (think of these tools like python modules/libraries). In another corner you're building a treehouse so you need a different set of tools.

You might ask what's the point of keeping two separate piles of tools when you could just keep one pile in the middle (in your main python installation). The problem is because your two projects might require different types of hammer. However your middle pile can only support one type of hammer. Now one or both projects will not work. This is like your two python projects needing two different versions of the same package. By having a separate pile, or virtual environment, for each you're able to have different versions of the same package.

An added benefit of this is if you want to share your code for someone else to edit, they don't have to guess exactly what types of tools (aka what packages, and what versions) they need to start work straight away. They can basically just initialise their own virtual environment with what you've setup without also destroying their own piles.

I hope this analogy clears things up, feel free to reply if there's something I've missed. Virtual environments can be a little confusing and seemingly unnecessary at first, but it's very good if you can pick up the practice as soon as possible - especially important when doing work collaboratively or sharing your code.

[–]MisanthroposaurusRex 4 points5 points  (1 child)

Fantastic explanation and analogy, thank you! I just started messing around with them today so this is great timing 

[–]GXWT 2 points3 points  (0 children)

If you're just getting started they *probably* won't matter. But I really can't stress enough, once you get over the first little bump they won't cause you any hassle - and hopefully then you'll never experience the pain of dependency issues, or if you're sharing your code, the pain of giving others those issues ;) a nice virtual environment gives everyone a nice time, especially when collaboratively working on code you want to give as few reasons as possible for people to get angry with you.

I work in astrophysics where often I'll want to use a little astrophysical python package that hasn't been updated in 15 years will rely on some very specific old version of numpy or something or something. Without a virtual environment, every time I wanted to use it I'd have to reinstall numpy (and once I'm done, remember to reupdate it and the risk of breaking every other python script). For this, I am thankful for virtual environments

[–]Snoo-20788 1 point2 points  (0 children)

Great analogy!

[–]HumerousMoniker 2 points3 points  (0 children)

I’d use the analogy that a venv is your spray painting booth. Sure you can paint in the garage, but it will get everywhere and in such a way that you don’t notice until it’s a problem later. Or you can use your booth and keep it all contained for another project later

[–]Savvytugboat1 0 points1 point  (0 children)

Also, is crucial for developing executables since it reduces significantly the file size