Python Tutorial: virtualenv and why you should use virtual environments

Corey Schafer · 871K views · 2015 · 9:46

Open on YouTube

Python, Ruby & scripting languagesTesting, debugging & developer toolstutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about juggling package or Python versions across projects, and when beginners need a walkthrough of creating and activating virtualenvs.

Recommended by 9 people across 9 different months, 2015 to 2021.

What it is

A roughly ten-minute Python tutorial by Corey Schafer explaining what virtual environments are and why to use them. It covers keeping project-specific dependencies out of the global site-packages and walks through creating and using virtualenv.

What people said

Recommends python · 2015-12 · Stack Overflow · on “How export python project?”

You have to use virtualenv when you are creating a python project with third party apps. virtualenv is a tool to create isolated Python environments. You can export this project and run in any other environment(Linux, Windows, OSX). Documentation - Virtualenv [LINK] Video - Virtualenv Tutorial [this video] You also need to create a requirement.txt file which will contain your all third party apps. Once you are in virtual environment, you could use the below code: pip freeze > requirement.txt it will create a requirement.txt file. For installing all the dependencies again, you need to use: pip install -r requirement.txt

Recommends Joseph Astrahan · 2017-01 · Stack Overflow · on “Upgrade Python on Mac from 2.7 to 3.6 (or newest) for elastic beanstalk client AWS”

watching a video here that really helped explained it for me ( [this video] ), giving this a try, its a cool idea.

Recommends Saeed · 2017-08 · Stack Overflow · on “Install older version of tensorflow”

I was able to solve the problem. If you to use certain version of a package for the a specific application, you can simply use virtualEN. Check out this tutorial [this video] .

Recommends Sudip Bhandari · 2018-05 · Stack Overflow · on “How to set Python 3 as default app?”

If you are going to be working on multiple python versions and their respective subpackages it's high time you started using python virtual environment. Why should you use python virtual environment [this video] By creating such virtual environments you can rest assured and work on projects dealing with different versions. Installation: sudo apt-get install python-virtualenv sudo easy_install virtualenv sudo pip install virtualenv Creating virtual environment folder: mkdir ~/.virtualenvironment Project and files which depend on this virtual env: virtualenv ~/virtualenvironment/my_new_app Activating the virtual env: cd ~/virtualenvironment/my_new_app/bin source activate Reference [LINK]

Recommends Leonardo Isso · 2019-01 · Stack Overflow · on “Having different versions of Python and Anaconda in same machine”

I'd recommend you using a virtual env for every project. Here's a pretty informative video: [this video] And the venv docs: [LINK]

Recommends skywallkee · 2020-08 · Stack Overflow · on “How to setup custom python version for your flask app to run?”

The best way to do this and with any other python project is to use virtual environments, as with them you can install/uninstall packages and manage their versions easily, thus being also able to choose which version you'd actually like to use. Here you have a link to the documentation of how to use virtual environments: [LINK] Also, I prefer using pipenv, if you'd like to look into it, here you can find how: [LINK] And a video tutorial if you'd really want someone talking while explaining and having a feel of how it looks like: [this video] Basically, with virtual environments you're setting up python packages per project , so that you can use for example different python versions, or different

Recommends sarartur · 2021-02 · Stack Overflow · on “Importing module from Github to use in Python”

Look at this [this video] tutorial. If you do know what virtual environment is that means all your packages are installed globally. You need to look for `site-packages` folder inside your python installation on your machine.

Recommends Eladtopaz · 2021-08 · Stack Overflow · on “How to import 2 versions of a package in Python?”

You could achieve this by using a virtual environment with venv module. Using venv you could have different directories with different versions of every library you want. Here are the docs: [LINK] And here is a good tutorial of how to really use this: [this video]

Recommends Himanshu Singh Chauhan · 2021-10 · Stack Overflow · on “How to change a python version, when creating a project in Xcode”

Learn how to use python virtual enviornment. I think you don't know what a virtual enviornment is you can move here -> [this video] and learn something new.

Cites Maddie Graham · 2018-07 · Stack Overflow · on “"no such file or directory python" activate environment for Python”

When i try activate Environments use cod $ source project1_env/bin/activate in Bash they returns the following message bash: project1_env/bin/activate: No such file or directory . Why I can't activate the environment? Environment vile is in the correct folder and inside them all look good. I use GIT Bash to Python 3.7 on Windows. [LINK] I think the answer can be very simple, but i do not see similar situation/ question on these forum. Thank you very much for your help! this is a conda environment you are trying to activate? – FlyingTeller I think it isn't. Properly the first steps they were the same how in these tutorial. [this video] (to 2:31 here i have i problem) What does ls -l project1_env/b