0

I have a highly counter-intuitive problem.

This virtual environment I've made is working spectacularly. I activate it, run my scripts, and they all work fine. However, once I delete my LOCAL installations of python.exe and pythonw.exe, the virtual environment launches, but the scripts fail to run, and Py Launcher complains about my pythonw.exe not existing!

I am explicitly running the virtual environment's python.exe and pythonw.exe by passing the absolute path to it, and then my .py file.

I need to share this script with a lot of people who don't have my local python installs, and yet they get the exact same error as me. Its almost like py.exe is categorically broken, because why should it be trying to launch python.exe that don't exist! The whole reason for Py Launcher is to avoid doing that.

Here is how I repro the problem.

  1. I launch my virtual environment by opening cmd and calling my activate.bat script
  2. I use the absolute path to my venv's pythonw.exe and launch server.py
  3. I am able to use my server, thus proving it works.
  4. I kill the python process, confirm my server is gone, and then I delete my only local installation of pythonw, which is here: "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\pythonw.exe"
  5. I then do steps 1 and 2 again.
  6. I get a pop up that says this:

enter image description here

Here is the command I use during steps 2 and 5. You can see that the virtual env is active, but as I state later, it shouldn't even need to be.

(venv) C:\Dev\grpc_server\source>"C:\Dev\grpc_server\venv\Scripts\pythonw.exe" server.py

This doesn't make sense on multiple levels:

  • Python Launcher is py.exe, and py.exe launches whichever python.exe it deems appropriate. Python.exe is never described as being the launcher of py.exe
  • This page states:

You don’t specifically need to activate a virtual environment, as you can just specify the full path to that environment’s Python interpreter when invoking Python.

That is incorrect. When I do that, like I said, py.exe is launched which then attempts to launch my local install.

I've also tried shebangs and actually using py.exe to launch the script, but the shebangs are ignored and it just tries to use the dang local install.

What is going on here?

  • The linked answer made me understand that Virtual Environments are NOT portable, or stand-alone. The word "virtual" does a ton of heavy lifting in it's name, because it isn't a real, whole 2nd environment. It still uses a bunch of hooks into other areas of your own system. I am pretty impressed I've gotten this far with virtual environments and either never read or never grasped that virtual environments are not a viable solution for deploying scripts on multiple systems. – Zoey Schlemper May 04 '23 at 22:44

0 Answers0