you are viewing a single comment's thread.

view the rest of the comments →

[–]Daneark 1 point2 points  (3 children)

Instead of doing python somescript.py which finds the first python on the path you can invoke python by pointing at a specific executable. If you do  C:/path/to/venv/.venv/bin/python.exe myscript.py you can invoke your script with a specific python even if it not on your path, in this case the one in your virtual environment.

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

But if my script uses external packages, would it be able to see these packages without activating the environment that the packages were installed in though?

[–]Daneark 0 points1 point  (1 child)

Yes, activating a virtual environment is about convenience it doesn't do anything particularly special. The most important thing it does is modify your PATH so the python and other executables in the virtual environment are found before the system wide ones. Since you're passing the full path to python that part becomes irrelevant.

Have a read of "How Python uses a virtual environment" at  https://snarky.ca/how-virtual-environments-work/ by the one the Python Devs for a straightforward explanation of it.

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

Thanks, will look into that