question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Installing additional python packages in running container is no longer recognised by vscode jupyter

See original GitHub issue

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

Steps

  • Start Docker container
  • Attach the container to VSCode using Remote - Containers
  • Open .jpynb
  • Either in terminal or in notebook cell run pip install package (package used was torchaudio and tgt)
  • restart notebook
  • import package
  • Error: ModuleNotFoundError: No module named 'tgt'

expectation and result

The package should be available in the notebook session after notebook restart but gets an error that the module is not found. (I have used these exact steps in the past without any issue)

I have tested this in a normal notebook session (running in the same container instance) via jupyter lab --ip 0.0.0.0 --no-browser, the package is installed and is seen by python as expected.

dockerfile

FROM pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtime
RUN apt-get update

## START - Creating user
RUN apt-get -y install sudo
RUN adduser --disabled-password --gecos '' user
RUN adduser user sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

RUN apt-get install -y tree \
                        libsndfile1 

## START - Jupyter notebook setup
RUN pip install jupyterlab

## START - Python packages
ADD requirements.txt .
RUN pip install -r requirements.txt
## END - Python packages

WORKDIR /workspace
RUN chown user:user /workspace
USER user

ENV type lab

CMD ["bash","-c", "jupyter ${type} --ip 0.0.0.0 --no-browser"]

VS Code Version

Version: 1.67.0 Commit: 57fd6d0195bb9b9d1b49f6da5db789060795de47 Date: 2022-05-04T12:08:42.978Z Electron: 17.4.1 Chromium: 98.0.4758.141 Node.js: 16.13.0 V8: 9.8.177.13-electron.0 OS: Linux x64 5.16.19-76051619-generic

Jupyter Extension Version

v2022.4.1011282140

Jupyter logs

info 13:43:49.771: Got new session e36d8642-720a-4ede-a5e2-91bcb3bf14f1
info 13:43:49.771: Started new restart session
info 13:43:49.772: Dispose Kernel process
info 13:43:49.774: Executing silently Code (idle) = import sys\nprint(sys.executable)
info 13:43:50.316: Executing silently Code (completed) = import sys\nprint(sys.executable)
info 13:43:50.450: UpdateWorkingDirectoryAndPath in Kernel
info 13:43:50.450: Executing silently Code (idle) = import os\nimport sys\n%cd "/workspace"\nif os.getcwd() not in sys.path:\nsys.path.insert(0, os.getc
info 13:43:50.463: Executing silently Code (completed) = import os\nimport sys\n%cd "/workspace"\nif os.getcwd() not in sys.path:\nsys.path.insert(0, os.getc
info 13:43:50.464: Waiting for idle on (kernel): e36d8642-720a-4ede-a5e2-91bcb3bf14f1 -> idle
info 13:43:50.464: Finished waiting for idle on (kernel): e36d8642-720a-4ede-a5e2-91bcb3bf14f1 -> idle
info 13:44:0.384: Execute Cell 0 /workspace/test.ipynb
info 13:44:0.477: Cell 0 executed with state Success
info 13:44:15.862: Execute Cell 6 /workspace/test.ipynb
info 13:44:17.476: Cancel all remaining cells true || Error || undefined
info 13:44:17.476: Cancel pending cells
info 13:44:17.476: Cell 6 executed with state Error

Coding Language and Runtime Version

Python 3.8

Language Extension Version (if applicable)

Pylance v2022.4.3

Anaconda Version (if applicable)

conda 4.11.0

Running Jupyter locally or remotely?

Remote

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
derekschinkecommented, May 12, 2022

Actually, that error is different and expected. Running it again with --user makes it seem like it installs as expected, but it actually doesn’t (running import <package> fails and returns ModuleNotFoundError). So I think it’s a similar issue.

Edit: submitted #9995

0reactions
DonJayamannecommented, Jun 23, 2022

Closing this issue as its been over 4 weeks, since the information was requested. We’ll be happy to reopen the issue when the requested information has been provided.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found error in VS code despite the fact that I ...
This answer solved my problem. Even though I set up a virtual environment, the integrated terminal was natively pointing at a different Python....
Read more >
Using Python environments in VS Code
An "environment" in Python is the context in which a Python program runs and consists of an interpreter and any number of installed...
Read more >
Working with Jupyter Notebooks in Visual Studio Code
To select an environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
Read more >
Settings Reference for Python - Visual Studio Code
Diagnostics for a variable that is not accessed. reportDuplicateImport, Diagnostics for an imported symbol or module that is imported more than once.
Read more >
Docker Tools Tips and Tricks - Visual Studio Code
If you select a port less than 1024 when adding Dockerfiles to the workspace, the Docker extension cannot create a Dockerfile that runs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found