Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLogesh Jayaraman
445 PointsVirtual environment
What is the advantage of using the virtual environment?
4 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsA virtual environment allows you to separate project specific versions of software and modules from your system level versions. This allows you to try various software versions without having to install everything at the system level
it also allows you to have two environments set up with conflicting requirements. For example one could be using python 2.7 and the other could be using python 3.5.
Using pip
freeze feature, you can get a list of all installed modules versions for a project that is using a specific virtual event. This list is often turned into a requirements.txt
file that can be used as the deployment requirements if the project is moved to another system.
Kevin Korte
28,149 PointsMy response is not specific to Python but in general, I think once you set up and see the benefits of a virtual environment, you'll always want to use one. I do that now, I don't really instal anything at the system level anymore. Everything gets installed in it's own little box.
Lance McCormick
7,553 PointsCan you explain or point to a good resource / guide to install creating virtual environments in Linux (Mint 17.3) ? I am struggling to get it working. I have pip3 installed and installed virtualenv using pip3. I cannot manage to create a new virtualenv in a project folder. Any help? (Mint comes with Python 3.4.3) I want to learn how to install newer versions of python and keep them in their own little boxes as you said. Thanks
Chris Freeman
Treehouse Moderator 68,454 PointsLance, It might be best to ask your question as a new post since is it not directly related to this topic. Thanks!
Erika Suzuki
20,299 PointsAmen to that.
ds1
7,627 PointsThanks, Chris... this is helpful! Though, I just realized that django is not fully supported except in the professional edition of PyCharm... which may be free to university students OR a person could use Atom or something else (I'm going to try Visual Studio Community 2017 and see if that works!) that supports django and is free if they wanted to run on something other than Workspaces.
Logesh Jayaraman
445 Pointsi am new to virtual env. Haven't used it but will try to use it. But i prefer not to go with virtual env
Erika Suzuki
20,299 PointsWhen you find yourself working with multiple websites. I think you will find it as the only way.
Kevin Korte
28,149 PointsAgreed, once you start having multiple projects going, it's the only way. No worrying about if this version of this is compatible with that version of that, because that's the version installed on your system, so all of your projects have to use it. Instead, every project has it's own neat box to contain everything in, and you can install exactly the versions you need, on a project by project basis with no bleed over.
Logesh Jayaraman
445 PointsThanks for your response Chris and Kevin
ds1
7,627 Pointsds1
7,627 PointsHi, Chris Freeman
Thanks for this. Though, I'm still stumped on the specifics. I installed virtualenvwrapper-win, then created a virtual environment for "learning_site" and then installed Django in there based on the general instructions at this link: https://docs.djangoproject.com/en/1.11/howto/windows/
I've been using PyCharm Edu 3.5.1 while working through the Learn Python tutorials and thought I could use PyCharm with the Django courses. I was wondering, how do I work with Django in PyCharm? i.e. do you know the specific steps I should take? (I guess technically, I don't have Django installed at the system-level yet [just in the learning_site virtual environment, if I'm understanding your and Kevin's posts correctly] but wanted to hold off until I understand what's what.)
Any help would be most appreciated. Thanks, D.
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsSorry, I'm not a PyCharm-er. I do most of my development using Emacs in a Linux environment (VirtualBox running Ubuntu guest OS on a Window host)
There maybe some way to run pycharm from "within" the virtual env. This may help: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html