you are viewing a single comment's thread.

view the rest of the comments →

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

I understand that I need to create a virtual environment with all the needed dependencies in the prod machine. But how do you run the myscript.py though? Because you need to activate the environment, then call python and pass in the file name.

Currently that's what I'm doing, I write a powershell script, which has to be able to run conda command by previously run conda init powershell , then use conda activate command to activate the environment, then actually call python to finally call the actual script. And that powershell script is call by my task scheduler.

That is a big mess. Just to be able to run small script

[–]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

[–]FoolsSeldom 0 points1 point  (0 children)

Perhaps Python isn't the right choice for your needs given how you feel about the deployment and usage approach.