joewalnes / websocketd

Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.
http://websocketd.com/
BSD 2-Clause "Simplified" License
17.14k stars 1.01k forks source link

ModuleNotFoundError under Python3's venv (virtual environment) #408

Closed bertlea closed 2 years ago

bertlea commented 3 years ago

version 0.4.1 platform Windows amd64

My Python3 program need to run under venv to access some modules only installed to the venv. After I entered the venv, I can run the program: main.py, then under the same venv, I attempted to run the websocketd:

websocketd --port=8080 py main.py

It spit out an error: "ModuleNotFoundError: No module named" and disconnected/terminated.

I wonder if there is some special settings / parameters I need to apply in order to run the Python program under venv. Or Python venv cannot be supported?

bertlea commented 3 years ago

I found a kind of work-around: use a .cmd batch file to set the environment PATH and then call the python program within that batch file. Then run the websocketd with that batch file. It seems to work, but not perfectly as when I exit the program, it will not disconnect, but stays in the Python interactive interpreter mode. I need to send "quit()" to fully quit and disconnect.

Somehow, I cannot use the Python venv scripts to entre the venv. Need manually set the PATH.

Not sure if this case can be closed. If there are better way, it will be nice to share.

asergeyev commented 3 years ago

I bet there are certain variables from your venv that aren't getting passed to make python work properly under websocketd...

Any experts here to know which addition to --passenv could help that?

asergeyev commented 3 years ago

What version of websocketd did you use? I'm pretty sure some of them did not pass enough vars on windows but new ones should have PATH and some others copied.