r/Python • • Apr 30 '18

xkcd: Python Environment

Post image
2.4k Upvotes

388 comments sorted by

View all comments

Show parent comments

1

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

Learning that all you need to do is #!/path/to/venv/bin/python in the script and it will just work was a game changer for me. I wrote little shell script wrappers sourcing activate forever.. really felt dumb when I discovered that :-)

4

u/[deleted] May 01 '18

You don't have to. In fact, I would recommend you avoid setting a specific path in your shebang line. Python is smart enough, that it detects when invoking something inside a virtual env, and will use the proper sys.path. Using "#! /usr/bin/env python3" (or python if that's your thing), is enough.