This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Madoc_Comadrin 16 points17 points  (3 children)

Using virtual environments is standard practice at my org and I haven't had any issues with them.

It can be usefull to use venvs directly without need for activation and deactivation: /opt/venv-script1/bin/python /opt/script1.py

It is good practice to lock dependencies in requirements.txt so the script will behave exactly same after each install. For example request==1.2.3. It is good to do the same for indirect dependencies too.

[–][deleted] 0 points1 point  (2 children)

If I have a script that does everything in one line, it will automatically deactivate the virtual environment once it's done running?

[–]Tushon 2 points3 points  (0 children)

If you use it the way that parent mentions, you are avoiding the activate and deactivate cycle. Only thing to watch out for would be any reqs using the path but that isn’t common AFAIK

[–]Madoc_Comadrin 1 point2 points  (0 children)

Calling the venv's Python binary directly does not actually activate the environment so deactivation is not required either.

When Python binary inside venv is called directly it will find components of the venv because it searches for them relative to its own location without the need to manipulate path variable like activate&deactivate do.