I’m trying to develop something using PyQt6, and I’ve run into a bit of an issue with VSCode. I’ve tried both using purely Nix and using a venv, but Nix makes the editor integration fail and venv makes the program fail to launch due to a missing libGL.so.1.
I have the following shell.nix:
{ pkgs ? import <nixpkgs> { } }:
let myPythonPkgs = pypkgs: with pypkgs; [
pyqt6
];
in pkgs.mkShell {
packages = with pkgs; [
(python3.withPackages myPythonPkgs)
];
}
I’m using the direnv extension to make this available in VSCode.
This causes a weird issue: Pylance picks up the modules but fails to pick up the identifiers exported by these modules. It shows no error on the imports but shows an error on every use of an identifier from these modules.
Does anybody know how I can get Pylance to recognize the modules introduced via Nix properly?
Just a guess, but does it work if you use python3.withPackages (...).env as the shell itself (for now)? That should properly set PYTHONPATH if your current shell doesn’t, and that should let Pylance pick up the modules.
Yes, that worked! Unfortunately now I don’t have the ability to add any additional external programs to the environment. Is there some way I can do that?
I was able to get it to recognize pwntools with python3.withPackages in users.user.<user>.packages
by adding the (sadly absolute) path of where it is installed in nix-store to settings.json as "python.analysis.extraPaths": [ "/nix/store/lkb8qcvlzaib80brshzf7pksgnd1xdnm-python3.10-pwntools-4.11.0/lib/python3.10/site-packages" ],
aquired through doing a pwd -P in /etc/profiles/per-user/<user>/lib/python3.10/site-packages/pwn