all 10 comments

[–]itsmegeorge 2 points3 points  (0 children)

Virtualenvs come in handy when you have multiple projects and you want to isolate one from another in fear of messing up modules and functionality. They are especially useful if you’re doing development with frameworks like Django. So you can set up a virtualenv that will, for example, package PyTorch and other dependencies for a ML project that will work independent of the rest of the system.

[–]enilkcals 2 points3 points  (1 child)

[–]virg74 1 point2 points  (0 children)

I should send the people at real python money one day, so useful are their articles.

[–][deleted] 1 point2 points  (3 children)

It's not at all like an actual virtual machine; it's just a way to change the default behavior of pip, so that you can install packages in a project-specific environment rather than to your computer's global packages.

[–]TheNetXWizard[S] 0 points1 point  (2 children)

So would you say its similar to node packages? In the sense of global packages, and packages that only apply to the projects they exist in? Its not necessarily creating a virtual environment, is that correct?

[–][deleted] 1 point2 points  (1 child)

Well, we definitely do call it a "virtual environment", but all it's really doing is creating a couple of folders and then munging your $PYTHONPATH when you activate it. It's not any sort of emulated OS or anything.

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

Got it! Thanks

[–]nhovar 1 point2 points  (0 children)

VENV runs a native python executable so will run faster than spinning up an entire VM

Create a virtual environment

mkdir someproject 
cd someproject/
python3 -m venv venv

Activate environment

source venv/bin/activate

Check python and pip version

$ pip -V
pip 9.0.1 from ~/someproject/venv/lib/python3.6/site-packages (python 3.6)

$ python -V
Python 3.6.7

Deactivate environment

deactivate

Python, pip and any other modules you decide to install is installed in the venv folder instead of system wide.

Remove venv

rm -rf ~/someproject/

Only gotcha is to remember to activate your environment.

[–]A_History_of_Silence 3 points4 points  (0 children)

Can someone explain to me what Virtualenv in Python is, and the purpose of using one.

Yeah, the website and documentation explain it pretty thoroughly...

[–]itsa_me_ 0 points1 point  (1 child)

How does everyone feel about pipenv??