r/Python • • Apr 30 '18

xkcd: Python Environment

Post image
2.4k Upvotes

388 comments sorted by

View all comments

413

u/ppgDa5id Apr 30 '18

For future reference, original link.
Because the real joke is in the title.

The Python environmental protection agency wants to seal it in a cement chamber, with pictoral messages to future civilizations warning them about the danger of using sudo to install random Python packages.

57

u/themonsterpus Apr 30 '18

Good point. Wasn't sure how well that work with all Reddit apps vs just the image but you do miss out on the alt text.

49

u/[deleted] Apr 30 '18

just link the website directly, this way you get /u/xkcd_bot and good apps/res will open the image with the title text.

17

u/[deleted] May 01 '18

I have been burned by sudo installing Python packages too many times. I should have heeded the warnings of my mentors and used venvs but in my noobie arrogance I thought I could get away with using sudo. Never again.

Everyone go pip install virtualenv and save yourselves while you have the chance.

0

u/[deleted] May 01 '18

[deleted]

→ More replies (1)

4

u/eazolan May 01 '18

I don't understand virtualenv.

Is there a good resource that explains it?

8

u/meandertothehorizon It works on my machine May 01 '18

Virtualenv copies and/or symlinks or hardlinks the files from system python necessary to create a second, segregated install in an arbitrary directory on your computer. You run/source a file from the command line in that directory (activate.sh/activate.bat) that modifies the environment to reference this copied version so anything you do - install packages, run python itself, etc will use this copy instead of system. This prevents clobbering the system setup if you install or upgrade arbitrary system packages. When you are done, or want to create another virtualenv, or run system python, you run ‘deactivate’ which will undo the environment modifications - so running python will again reference the system python. Any packages you installed will be ‘gone’ because they reside in the copied environment.

4

u/cocorebop May 01 '18

To give you a short explanation that won't tell you what it is but might give you an intuitive understanding of what it does:

When I turn on my computer at work and open the terminal, I have my default python environment.

When I type workon py3_env, I enter an environment I made called "py3_env". This has python 3.6 as the default, and has all the packages I need to run my development environment already installed.

When I type workon chess_thing_ts2, I switch to a new python environment for a little game I'm working on in my own time. For argument's sake, this environment has python 2.7 as the default, and has only the packages required to run my game app.

It's basically a way for you to put workspaces into buckets.

→ More replies (2)
→ More replies (9)

6

u/vingrish May 01 '18

pyenv + virtualenv is good.

2

u/gangtraet May 01 '18

pip install --user

Followed by nuking ~/.local when you mess up.

→ More replies (1)
→ More replies (1)

28

u/seishi Apr 30 '18

I still think the discussion surrounding how to convey that an area (such as Yucca Mountain) is dangerous to future civilizations is fascinating. I was first introduced to it during one of my Human-Computer Interaction courses and it has stuck with me.

I highly recommend the book "The Design of Everyday Things" as a primer. Even after all these years, the principles in it make me look at things differently, and I'm not even a designer by any means.

http://www.slate.com/articles/health_and_science/green_room/2009/11/atomic_priesthoods_thorn_landscapes_and_munchian_pictograms.html

→ More replies (1)