Python Modules - Websocket Module

How can I use a python module, specifically the websocket module?
It’s really strange. I’ve tried installing python310Packages.websockets and python310 but it won’t let me use the websockets module.
My code just errors out with ModuleNotFoundError: No module named 'websockets'.

Also tried other python versions.
If I execute nix-shell -p python310Packages.websockets and run my python code, then python can take advantage of the websockets module. How can I fix this so I can permanently install the websockets python module usable?

You don’t “install python and the websockets module”, you “install a python with the websockets module”. python3.withPackages (ps: with ps; [ websockets ]) is the syntax for that. (Don’t forget parens if you put that expression into a list, or it will be parsed as 2 sequential list elements).

nix-shell -p works because it’s really creating a package build environment under the hood, which is a whole other can of worms.

1 Like

When adding the line (python3.withPackages (ps: with ps; [ websockets ])) to my systemPackages it now works.
Thank you.