Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Import could not be resolved" for local packages and modules #3035

Closed
dariush-bahrami opened this issue Jul 8, 2022 · 9 comments
Closed
Labels
bug Something isn't working

Comments

@dariush-bahrami
Copy link

Environment data

  • VS Code version: 1.69.0
  • Jupyter Extension version (available under the Extensions sidebar): v2022.6.1001902341
  • Python Extension version (available under the Extensions sidebar): v2022.10.0
  • OS and version: Windows 11 (build 22621.160)
  • Python and/or Anaconda version: 3.10.5
  • Type of virtual environment used: conda
  • Jupyter server running: Local

Expected behaviour

To recognize local packages and modules (as in python scripts)

Actual behaviour

highlighting local imports with a wavy underline with the message: Import "mypackage" could not be resolved

vscode_jupyter_not_resolved_import

Note: in the provided screenshot, it is clear that this is a problem with the notebook, not the python extension in general.

Steps to reproduce:

  1. Create a python package or module
  2. Create a jupyter notebook (.ipynb file)
  3. Import created package at step 1 in the notebook

Logs

Visual Studio Code (1.69.0, undefined, desktop)
Jupyter Extension Version: 2022.6.1001902341.
Python Extension Version: 2022.10.0.
Workspace folder d:\projects\bugs
info 17:35:35.353: ZMQ install verified.
User belongs to experiment group 'jupyterTest'
User belongs to experiment group 'jupyterEnhancedDataViewer'
info 17:35:35.656: LSP Notebooks experiment is enabled
info 17:35:36.487: Experiment status for python is {"enabled":true,"optInto":[],"optOutFrom":[]}
info 17:35:36.539: Preferred Remote kernel for d:\projects\bugs\notebook.ipynb is undefined
info 17:35:36.539: Find preferred kernel for d:\projects\bugs\notebook.ipynb with metadata {"orig_nbformat":4,"language_info":{"name":"python"}} & preferred interpreter c:\Users\dariush\miniforge3\envs\myenv\python.exe
info 17:35:36.542: Preferred Remote kernel for d:\projects\bugs\notebook.ipynb is undefined
info 17:35:36.542: Preferred kernel .jvsc74a57bd0ff0a4987fe7a5516b553766a9217bc68eb8628ec85781c7ad0909113903e0020.c:\Users\dariush\miniforge3\envs\myenv\python.exe.c:\Users\dariush\miniforge3\envs\myenv\python.exe.-m#ipykernel_launcher is exact match
info 17:35:36.543: PreferredConnection: .jvsc74a57bd0ff0a4987fe7a5516b553766a9217bc68eb8628ec85781c7ad0909113903e0020.c:\Users\dariush\miniforge3\envs\myenv\python.exe.c:\Users\dariush\miniforge3\envs\myenv\python.exe.-m#ipykernel_launcher found for NotebookDocument: d:\projects\bugs\notebook.ipynb
info 17:35:36.550: Process Execution: > ~\miniforge3\envs\myenv\python.exe -m pip list
> ~\miniforge3\envs\myenv\python.exe -m pip list
info 17:35:37.442: Preferred Remote kernel for d:\projects\bugs\notebook.ipynb is undefined
info 17:35:37.442: Find preferred kernel for d:\projects\bugs\notebook.ipynb with metadata {"orig_nbformat":4,"language_info":{"name":"python"}} & preferred interpreter c:\Users\dariush\miniforge3\envs\myenv\python.exe
info 17:35:37.444: Preferred Remote kernel for d:\projects\bugs\notebook.ipynb is undefined
info 17:35:37.444: Preferred kernel .jvsc74a57bd0ff0a4987fe7a5516b553766a9217bc68eb8628ec85781c7ad0909113903e0020.c:\Users\dariush\miniforge3\envs\myenv\python.exe.c:\Users\dariush\miniforge3\envs\myenv\python.exe.-m#ipykernel_launcher is exact match
info 17:35:37.445: Preferred Remote kernel for d:\projects\bugs\notebook.ipynb is undefined
info 17:35:40.994: Starting Jupyter Session id = 'startUsingPythonInterpreter:.jvsc74a57bd0ff0a4987fe7a5516b553766a9217bc68eb8628ec85781c7ad0909113903e0020.c:\Users\dariush\miniforge3\envs\myenv\python.exe.c:\Users\dariush\miniforge3\envs\myenv\python.exe.-m#ipykernel_launcher' (Python Path: c:\Users\dariush\miniforge3\envs\myenv, EnvType: Conda, EnvName: 'myenv', Version: 3.10.5) for 'd:\projects\bugs\notebook.ipynb' (disableUI=true)
info 17:35:40.995: Creating raw notebook for resource 'd:\projects\bugs\notebook.ipynb'
info 17:35:40.995: Computing working directory for resource 'd:\projects\bugs\notebook.ipynb'
info 17:35:41.20: Starting raw kernel 'myenv (Python 3.10.5)' for interpreter c:\Users\dariush\miniforge3\envs\myenv\python.exe
info 17:35:41.61: Kernel launching with ports 9000,9001,9002,9003,9004. Start port is 9000
info 17:35:41.66: Process Execution: > ~\miniforge3\envs\myenv\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> ~\miniforge3\envs\myenv\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
info 17:35:41.99: Creating daemon process for c:\Users\dariush\miniforge3\envs\myenv\python.exe with env variables count 64
info 17:35:41.103: Process Execution: > ~\miniforge3\envs\myenv\python.exe -m vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_interrupt_daemon -v --ppid 16040
> ~\miniforge3\envs\myenv\python.exe -m vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_interrupt_daemon -v --ppid 16040
info 17:35:41.338: get interrupthandle daemon
info 17:35:41.343: Process Execution: > ~\miniforge3\envs\myenv\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"2a6cd56c-256f-4a88-b3b0-685a4b488b87" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\dariush\AppData\Roaming\jupyter\runtime\kernel-v2-16040HnxfnN5XtDwc.json
> ~\miniforge3\envs\myenv\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"2a6cd56c-256f-4a88-b3b0-685a4b488b87" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\dariush\AppData\Roaming\jupyter\runtime\kernel-v2-16040HnxfnN5XtDwc.json
info 17:35:41.343: Process Execution: cwd: d:\projects\bugs
cwd: d:\projects\bugs
info 17:35:41.610: ipykernel version 6.15.0 for c:\Users\dariush\miniforge3\envs\myenv\python.exe
info 17:35:41.610: ipykernel location ~\miniforge3\envs\myenv\lib\site-packages\ipykernel\__init__.py for c:\Users\dariush\miniforge3\envs\myenv\python.exe
warn 17:35:42.777: StdErr from Kernel Process c:\Users\dariush\miniforge3\envs\myenv\lib\site-packages\traitlets\traitlets.py:2392: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(

warn 17:35:42.777: StdErr from Kernel Process c:\Users\dariush\miniforge3\envs\myenv\lib\site-packages\traitlets\traitlets.py:2346: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use '2a6cd56c-256f-4a88-b3b0-685a4b488b87' instead of 'b"2a6cd56c-256f-4a88-b3b0-685a4b488b87"'.
  warn(

info 17:35:42.864: Kernel Output: NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049


To connect another client to this kernel, use:
    --existing c:\Users\dariush\AppData\Roaming\jupyter\runtime\kernel-v2-16040HnxfnN5XtDwc.json

info 17:35:43.32: Started kernel myenv (Python 3.10.5)., (Raw session started and connected)
info 17:35:43.33: Finished connecting 77698eb3-0340-4306-ac43-d152a89a6550
info 17:35:43.34: UpdateWorkingDirectoryAndPath in Kernel
info 17:35:43.34: Executing silently Code (idle) = import os\nimport sys\n%cd "d:\projects\bugs"\nif os.getcwd() not in sys.path:\nsys.path.insert(0, o
info 17:35:43.69: Executing silently Code (completed) = import os\nimport sys\n%cd "d:\projects\bugs"\nif os.getcwd() not in sys.path:\nsys.path.insert(0, o with 1 output(s)
info 17:35:43.70: Executing silently Code (idle) = %load_ext autoreload\n%autoreload 2
info 17:35:43.117: Executing silently Code (completed) = %load_ext autoreload\n%autoreload 2 with 0 output(s)
info 17:35:43.117: Waiting for idle on (kernel): 2a7a7fd3-80b4-4a4b-8d8f-ff52ad2d8184 -> idle
info 17:35:43.117: Finished waiting for idle on (kernel): 2a7a7fd3-80b4-4a4b-8d8f-ff52ad2d8184 -> idle
info 17:35:43.127: Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
info 17:35:43.127: Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
error 17:35:43.134: Failed to get baseUrl [Error: ENOENT: no such file or directory, lstat 'c:\Users\dariush\miniforge3\envs\myenv\share\jupyter\nbextensions'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'c:\\Users\\dariush\\miniforge3\\envs\\myenv\\share\\jupyter\\nbextensions'
}
info 17:36:16.46: Execute Cell 0 d:\projects\bugs\notebook.ipynb
info 17:36:16.132: Cell 0 executed with state Success

@dariush-bahrami dariush-bahrami added the bug Something isn't working label Jul 8, 2022
@amunger
Copy link

amunger commented Jul 11, 2022

Do you have the same python environment selected for the notebook's kernel as your active python interpreter ('myenv': conda)?
The kernel picker is at the top left of the notebook window, behind the popup in that screenshot.

If you run a cell so that the kernel is started, does the warning go away?

@dariush-bahrami
Copy link
Author

Hi, yes the environment is the same for both the notebook and python script file. I recorded the process:
jupyter_import_bug

@rchiodo rchiodo transferred this issue from microsoft/vscode-jupyter Jul 12, 2022
@amunger amunger removed their assignment Jul 12, 2022
@heejaechang
Copy link
Contributor

looks like we have set wrong root for notebook. you can set "python.pylanceLspNotebooksEnabled": false, in user settings.json (not workspace settings.json) for now until we fix the issue. that will let you use our old notebook support if you want.

@judej
Copy link
Contributor

judej commented Jul 13, 2022

Dupe of #3017

@judej judej closed this as completed Jul 13, 2022
@mabodofutk
Copy link

As of this version of vscode:

Version: 1.71.0 (Universal)
Commit: 784b0177c56c607789f9638da7b6bf3230d47a8c
Date: 2022-09-01T07:25:38.437Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin x64 21.5.0
Sandboxed: No

this issue still exists.

"python.pylanceLspNotebooksEnabled": false, this solution is needed for me to resolve it.

@rafaelugolini
Copy link

I still have the same issue

Version: 1.72.0-insider
Commit: daf5eb22623fb2cc586453147fc4dab98cf10b1d
Date: 2022-09-06T10:38:05.259Z (4 hrs ago)
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin arm64 21.6.0
Sandboxed: Yes

Pylance: 2022.8.51 (31 August 2022) PreRelease

@torext
Copy link

torext commented Sep 9, 2022

Also here still the same issue

Version: 1.71.0
Commit: 784b0177c56c607789f9638da7b6bf3230d47a8c
Date: 2022-09-01T07:25:10.472Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 5.15.0-46-generic
Sandboxed: No
Extensions (12)
Extension Author (truncated) Version
gitlens eam 12.2.2
latex-workshop Jam 8.29.0
vsc-python-indent Kev 1.17.0
python ms- 2022.14.0
vscode-pylance ms- 2022.9.10
jupyter ms- 2022.8.1002431955
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.9
remote-ssh ms- 0.84.0
remote-ssh-edit ms- 0.80.0
autodocstring njp 0.6.1
vim vsc 1.23.2

@dengchenlong
Copy link

Similar case but not same, Simply installing ipykernel worked for me.
conda install ipykernel

@heejaechang
Copy link
Contributor

this issue is closed. please open new issue even if the symptom looks similar. otherwise, not sure whether people will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants