I use VSCode in an interactive online session as explained here:
I have installed packages using pip install -m requirements.txt, and am now trying to import these packages in a python script called MyScript.py. When running this python script from a command terminal using python MyScript.py, everything works fine.
But when I start the script from within VSCode (“Run/Debug python file in terminal”), it cannot find the module (No module named ‘XYZ’).
Also, clicking the green “Start debugging (F5)” arrow does not follow the currently selected Debug configuration from .vscode/launch.json but ask me everytime to “Select a Debug Configuration”. What is up with that?
Hi @dennis-beermann, thanks for reaching out! My first instinct is to double-check that you are using the correct python environment when running the script in VSCode - it doesn’t always select the correct one per default. If this is a project you can share, I’m happy to take a look.
However, if you are already a VSCode user you might find it nicer to work in VSCode through a remote SSH connection to your session. The documentation on how to do this is here.
First of all thanks for the input! I have not set up any python environments, so I would be grateful if you could take a look. The project is just barebones at the moment, I literally only added the imported module and a script trying to call it:
The local-IDE-path you described sounds nice as well. However, I have to sort out some WSL issues on my side before I can try that.
Hi @dennis-beermann ! Have you tried creating a virtual environment as explained here? I happened to face similar issues in the past and everything was solved when working from a virtual environment in VSCode. I have tested the solution locally in my computer and it works:
If you click on it, you can change it to the conda one (which it highlights as “Recommended” - not sure why it’s not automatically selected!). Then the python tooling should work correctly for your project.
Btw, I realized that there is now an easier way to install the code-server. Instead of modifying the Dockerfile, you can simply change the environment.yml file like this:
Thanks @elisabetc and @rrrrrok for your answers. I know about venvs but my main issue was that I could not locate a way to select the interpreter. This very much solves my initial issue!!
One last thing since you brought it up: I have update the environment.yaml as suggested and taken out the code-server line in the Dockerfile, then commited my changes. Works great! However, if I do the same on a new repo (Reproducible Data Science | Open Research | Renku), how do I actually get a link to the VS Code notepad in the Launcher?