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

Automatically load python modules by Jupyter Notebook in VS code #16168

Open
luomeng007 opened this issue Oct 29, 2024 · 10 comments
Open

Automatically load python modules by Jupyter Notebook in VS code #16168

luomeng007 opened this issue Oct 29, 2024 · 10 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel)

Comments

@luomeng007
Copy link

Environment data

  • VS Code version: 1.94.2
  • Jupyter Extension version (available under the Extensions sidebar): v2024.9.1
  • Python Extension version (available under the Extensions sidebar): v2024.16.1
  • OS (Windows | Mac | Linux distro) and version: Windows
  • Python and/or Anaconda version: 3.11.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): Python root
  • Jupyter server running: Local

Expected behaviour

I created two files, the one is called test_import.py, the code inside is as below:

def Debug():
    return 42

And another file is called Debug01.ipynb, which is a Jupyter Notebook file. The code inside it is:

import Test_import as t

result = t.Debug()
print(result)

Finally, according to someone's advice on Stackoverflow, I put the code below inside ./vscode/settings.json file.

"jupyter.runStartupCommands": [
   "%load_ext autoreload",
   "%autoreload 2",
]

What I want to realize is that, when I run the code inside Debug01.ipynb file, I should get result 42, and then I go to test_import.py to change the return value to 43. Then I run the code inside Debug01.ipynb file, I should get result 43 rather than 42.

For running the code, I mean I only need to 'Run All' button in jupyter rather than 'Restart'.

Actual behaviour

When I change the return value in test_import.py from 42 to 43, after running the code inside Debug01.ipynb the second time, I still get 42.

Steps to reproduce:

You can create a new workspace, and create two files like what I did and then try this, you should get same reuslt.

@luomeng007 luomeng007 added the bug Issue identified by VS Code Team member as probable bug label Oct 29, 2024
@DonJayamanne
Copy link
Contributor

Please could you enable logging as follows:

  • Open settings & go into Jupyter->Logging
  • Change the value to trace
  • Reload VS Code,
  • Attempt to repro the issue & then copy the output from the Jupyter output panel (use the command Jupyter: Show Output to get to the logs).

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) labels Oct 29, 2024
@luomeng007
Copy link
Author

luomeng007 commented Oct 29, 2024

The information of log is as below:

Visual Studio Code (1.94.2, undefined, desktop)
Jupyter Extension Version: 2024.9.1.
Python Extension Version: 2024.16.1.
Pylance Extension Version: 2024.10.1.
Platform: win32 (x64).
Temp Storage folder ~\AppData\Roaming\Code\User\globalStorage\ms-toolsai.jupyter\version-2024.9.1
Workspace folder ~\Desktop\GDSFactoryHGXS, Home = c:\Users\luome
18:12:41.912 [debug] Start refreshing Kernel Picker (1730196761911)
18:12:42.066 [trace] Search for KernelSpecs in Interpreter c:\Softwares\Python 3.11.5\python.exe
18:12:42.069 [debug] Get Custom Env Variables, Class name = Cm, completed in 158ms, has a truthy return value, Arg 1: undefined, Arg 2: "RunPythonCode"
18:12:42.069 [debug] Jupyter Paths kernels: 
18:12:42.069 [debug] Kernel Spec Root Paths, ~\AppData\Roaming\jupyter\kernels, c:\ProgramData\jupyter\kernels
18:12:42.073 [debug] Start refreshing Interpreter Kernel Picker
18:12:42.570 [debug] KernelProvider switched kernel to id = .jvsc74a57bd0082ec931ec2952f4f77f07dc32398e2c37739e3dbe5ce664d7381345381aadf3.c:\Softwares\Python 3.11.5\python.exe.c:\Softwares\Python 3.11.5\python.exe.-m#ipykernel_launcher
18:12:42.570 [debug] start the kernel, options.disableUI=true for ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb
18:12:42.572 [debug] Controller selection change completed
18:12:42.624 [trace] Registering commtarget jupyter.widget
18:12:42.699 [debug] Get Custom Env Variables, Class name = Cm, completed in 0ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS", Arg 2: "RunPythonCode"
18:12:42.700 [info] Starting Kernel (Python Path: c:\Softwares\Python 3.11.5\python.exe, Unknown, 3.11.5) for '~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb' (disableUI=true)
18:12:42.702 [trace] Creating raw notebook for resource '~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb'
18:12:42.855 [debug] Get Custom Env Variables, Class name = Cm, completed in 0ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Debug01.ipynb", Arg 2: "RunPythonCode"
18:12:42.912 [trace] Hiding default KernelSpec python for interpreter c:\Softwares\Python 3.11.5\python.exe (KernelSpec file c:\Softwares\Python 3.11.5\share\jupyter\kernels\python3\kernel.json)
18:12:43.000 [debug] Launching kernel .jvsc74a57bd0082ec931ec2952f4f77f07dc32398e2c37739e3dbe5ce664d7381345381aadf3.c:\Softwares\Python 3.11.5\python.exe.c:\Softwares\Python 3.11.5\python.exe.-m#ipykernel_launcher for ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb in ~\Desktop\GDSFactoryHGXS with ports 9001, 9000, 9004, 9002, 9003
18:12:43.006 [warn] Failed to get activated env vars for c:\Softwares\Python 3.11.5\python.exe in 306ms
18:12:43.007 [debug] Create ProcessService, Class name = Sm (started execution), Arg 1: undefined
18:12:43.009 [debug] Get Custom Env Variables, Class name = Cm, completed in 2ms, has a truthy return value, Arg 1: undefined, Arg 2: "RunNonPythonCode", Arg 3: undefined
18:12:43.009 [debug] Create ProcessService, Class name = Sm, completed in 2ms, has a truthy return value, Arg 1: undefined
18:12:43.018 [info] Process Execution: c:\Softwares\Python 3.11.5\python.exe -c "import site;print("USER_BASE_VALUE");print(site.USER_SITE);print("USER_BASE_VALUE");"
18:12:43.032 [warn] Failed to get activated env vars for c:\Softwares\Python 3.11.5\python.exe in 177ms
18:12:43.060 [trace] USER_SITE for c:\Softwares\Python 3.11.5\python.exe is c:\Users\~\AppData\Roaming\Python\Python311\Scripts
18:12:43.061 [trace] Prepend PATH with user site path for c:\Softwares\Python 3.11.5\python.exe, user site c:\Users\~\AppData\Roaming\Python\Python311\Scripts
18:12:43.061 [trace] Prepend PATH with python bin for c:\Softwares\Python 3.11.5\python.exe
18:12:43.062 [trace] Prepend PATH with user site path for c:\Softwares\Python 3.11.5\python.exe, user site c:\Users\~\AppData\Roaming\Python\Python311\Scripts
18:12:43.062 [trace] Prepend PATH with python bin for c:\Softwares\Python 3.11.5\python.exe
18:12:43.063 [debug] Getting activated env variables, Class name = gd, completed in 365ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS", Arg 2: "C:\\SOFTWARES\\PYTHON 3.11.5\\PYTHON.EXE", Arg 3: undefined
18:12:43.063 [debug] Getting activated env variables, Class name = gd, completed in 208ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Debug01.ipynb", Arg 2: "C:\\SOFTWARES\\PYTHON 3.11.5\\PYTHON.EXE", Arg 3: undefined
18:12:43.074 [info] Process Execution: c:\Softwares\Python 3.11.5\python.exe -m pip list
18:12:43.082 [info] Process Execution: c:\Softwares\Python 3.11.5\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
18:12:43.092 [info] Process Execution: c:\Softwares\Python 3.11.5\python.exe c:\Users\~\.vscode\extensions\ms-toolsai.jupyter-2024.9.1-win32-x64\pythonFiles\vscode_datascience_helpers\kernel_interrupt_daemon.py --ppid 21356
    > cwd: ~\.vscode\extensions\ms-toolsai.jupyter-2024.9.1-win32-x64\pythonFiles\vscode_datascience_helpers
18:12:43.379 [trace] Got a response of 1628 for INITIALIZE_INTERRUPT:0
18:12:43.390 [info] Process Execution: c:\Softwares\Python 3.11.5\python.exe -m ipykernel_launcher --f=c:\Users\~\AppData\Roaming\jupyter\runtime\kernel-v30f4426b9640550b338ddd641d83466fbd37259fe.json
    > cwd: ~\Desktop\GDSFactoryHGXS
18:12:43.390 [debug] Kernel process 18180.
18:12:43.450 [trace] Conda file is conda
18:12:43.455 [trace] Python API env change detected, update => 'C:\SOFTWARES\PYTHON 3.11.5\PYTHON.EXE'
18:12:43.458 [debug] Refreshed Environments
18:12:43.542 [trace] ipykernel version & path 6.29.5, c:\Softwares\Python 3.11.5\Lib\site-packages\ipykernel\__init__.py for c:\Softwares\Python 3.11.5\python.exe
18:12:44.014 [debug] Interpreter for Pylance for Notebook URI "~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb" is c:\Softwares\Python 3.11.5\python.exe
18:12:44.306 [debug] KernelProcess error 18180: [IPKernelApp] ERROR | Exception while loading config file C:\Users\~\.ipython\profile_default\ipython_config.py
Traceback (most recent call last):
  File "c:\Softwares\Python 3.11.5\Lib\site-packages\traitlets\config\application.py", line 915, in _load_config_files
    config = loader.load_config()
             ^^^^^^^^^^^^^^^^^^^^
  File "c:\Softwares\Python 3.11.5\Lib\site-packages\traitlets\config\loader.py", line 622, in load_config
    self._read_file_as_dict()
  File "c:\Softwares\Python 3.11.5\Lib\site-packages\traitlets\config\loader.py", line 655, in _read_file_as_dict
    exec(compile(f.read(), conf_filename, "exec"), namespace, namespace)  # noqa: S102
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\~\.ipython\profile_default\ipython_config.py", line 1343
    ]
    ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 31-32: truncated \UXXXXXXXX escape

18:12:44.416 [debug] Kernel output 18180: To connect another client to this kernel, use:
--existing c:\Users\~\AppData\Roaming\jupyter\runtime\kernel-v30f4426b9640550b338ddd641d83466fbd37259fe.json
18:12:44.478 [debug] Waiting for Raw Session to be ready in postStartRawSession
18:12:44.479 [debug] Waiting for Raw session to be ready, status: connected
18:12:44.479 [trace] Raw session connected
18:12:44.480 [debug] Waited for Raw session to be ready & got status: connected
18:12:44.480 [debug] Successfully waited for Raw Session to be ready in postStartRawSession
18:12:44.480 [debug] Kernel status is 'unknown' before requesting kernel info and after ready
18:12:44.480 [debug] Sending request for kernelInfo
18:12:44.481 [debug] End refreshing Kernel Picker (1730196761911)
18:12:44.566 [debug] Handle Execution of Cells 0 for ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb
18:12:44.567 [trace] Execute Notebook ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb. Step 1
18:12:44.567 [trace] Connect to Kernel ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb. Step 2
18:12:44.578 [trace] Got response for requestKernelInfo
18:12:44.578 [debug] Successfully completed postStartRawSession after 1 attempt(s) in 98ms
18:12:44.580 [trace] Executing silently Code (idle) = import sys as _VSCODE_sys\nprint(_VSCODE_sys.executable); del _VSCODE_sys
18:12:44.589 [trace] Executing silently Code (completed) = import sys as _VSCODE_sys\nprint(_VSCODE_sys.executable); del _VSCODE_sys with 1 output(s)
18:12:44.589 [trace] Started running kernel initialization for ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb
18:12:44.590 [trace] Executing silently Code (idle) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy
18:12:44.662 [trace] Executing silently Code (completed) = try:\nimport ipywidgets as _VSCODE_ipywidgets\nprint("e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPy with 1 output(s)
18:12:44.662 [trace] Determined IPyWidgets Version as 8
18:12:44.663 [trace] Version of IPyWidgets 8 determined after 2.038s
18:12:44.663 [trace] Version of IPyWidgets 8 determined after 2.013s
18:12:44.664 [trace] Executing silently Code (idle) = def __VSCODE_inject_module():\ndef __VSCODE_call_function(function, callback, data=None):
18:12:44.681 [trace] Executing silently Code (completed) = def __VSCODE_inject_module():\ndef __VSCODE_call_function(function, callback, data=None): with 0 output(s)
18:12:44.682 [debug] Requesting Kernel info
18:12:44.682 [trace] Got Kernel info
18:12:44.682 [trace] End running kernel initialization, now waiting for idle
18:12:44.682 [trace] Waiting for idle on (kernel): 8bf59dcb-58a2-4a27-b366-ab6491425dd9 -> idle
18:12:44.683 [trace] Finished waiting for idle on (kernel): 8bf59dcb-58a2-4a27-b366-ab6491425dd9 -> idle
18:12:44.683 [trace] End running kernel initialization, session is idle
18:12:44.684 [trace] Registering Kernel Completion Provider from kernel Python 3.11.5 for language python
18:12:44.685 [trace] IPyWidgetScriptSource.initialize
18:12:44.685 [info] Kernel successfully started
18:12:44.687 [debug] getDataDirsImpl, Class name = Mr (started execution), Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Debug01.ipynb", Arg 2: "C:\\SOFTWARES\\PYTHON 3.11.5\\PYTHON.EXE"
18:12:44.688 [debug] Get Custom Env Variables, Class name = Cm, completed in 1ms, has a truthy return value, Arg 1: undefined, Arg 2: "RunPythonCode"
18:12:44.689 [debug] Jupyter Paths : 
18:12:44.689 [trace] Connected to Kernel ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb. Step 3
18:12:44.690 [trace] executeCell 0. Step 4
18:12:44.694 [trace] Cell Index:0 sent to kernel
18:12:44.696 [debug] Get Custom Env Variables, Class name = Cm, completed in 1ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Debug01.ipynb", Arg 2: "RunPythonCode"
18:12:44.702 [trace] Start cell 0 execution @ 1730196764701 (clear output)
18:12:44.703 [debug] Kernel acknowledged execution of cell 0 @ 1730196764701
18:12:44.710 [trace] Cell 0 completed in 0.008s (start: 1730196764701, end: 1730196764709)
18:12:44.710 [trace] Cell 0 executed successfully
18:12:44.730 [warn] Failed to get activated env vars for c:\Softwares\Python 3.11.5\python.exe in 35ms
18:12:44.731 [trace] Prepend PATH with user site path for c:\Softwares\Python 3.11.5\python.exe, user site c:\Users\~\AppData\Roaming\Python\Python311\Scripts
18:12:44.731 [trace] Prepend PATH with python bin for c:\Softwares\Python 3.11.5\python.exe
18:12:44.731 [debug] Getting activated env variables, Class name = gd, completed in 36ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Debug01.ipynb", Arg 2: "C:\\SOFTWARES\\PYTHON 3.11.5\\PYTHON.EXE", Arg 3: undefined
18:12:44.744 [info] Process Execution: c:\Softwares\Python 3.11.5\python.exe c:\Users\~\.vscode\extensions\ms-toolsai.jupyter-2024.9.1-win32-x64\pythonFiles\printJupyterDataDir.py
18:12:44.794 [debug] getDataDirsImpl, Class name = Mr, completed in 107ms, has a truthy return value, Arg 1: "/c:/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Debug01.ipynb", Arg 2: "C:\\SOFTWARES\\PYTHON 3.11.5\\PYTHON.EXE", Return Value: <Uri:/C:/Users/~/AppData/Roaming/jupyter>, <Uri:/C:/Softwares/Python 3.11.5/share/jupyter>, <Uri:/C:/ProgramData/jupyter>
18:12:45.201 [trace] Web view is ready to receive widget messages
18:12:45.208 [trace] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
18:12:45.209 [trace] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
18:12:45.220 [trace] Widget Message: data-base-url set to https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter
18:12:45.221 [trace] Widget Message: Received IPyWidgets_kernelOptions in ScriptManager
18:12:45.221 [trace] Widget Message: Received IPyWidgetMessages.IPyWidgets_kernelOptions
18:12:45.221 [trace] Widget Message: data-base-url set to https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter
18:12:45.518 [trace] Widget Message: Received IPyWidget scripts [{"moduleName":"ipytree","scriptUri":"https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/ipytree/index","source":"local"}]
18:12:45.519 [trace] Widget Message: Source for IPyWidget ipytree found in local @ https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/ipytree/index.
18:12:45.519 [trace] Widget Message: Registering IPyWidget ipytree found in https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/ipytree/index.
18:12:45.520 [trace] Widget Message: Received IPyWidget scripts [{"moduleName":"jupyter-cytoscape","scriptUri":"https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/jupyter-cytoscape/index","source":"local"}]
18:12:45.521 [trace] Widget Message: Source for IPyWidget jupyter-cytoscape found in local @ https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/jupyter-cytoscape/index.
18:12:45.521 [trace] Widget Message: Registering IPyWidget jupyter-cytoscape found in https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/jupyter-cytoscape/index.
18:12:45.525 [trace] Widget Message: Received IPyWidget scripts [{"moduleName":"jupyter-matplotlib","scriptUri":"https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/jupyter-matplotlib/index","source":"local"}]
18:12:45.526 [trace] Widget Message: Source for IPyWidget jupyter-matplotlib found in local @ https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/jupyter-matplotlib/index.
18:12:45.527 [trace] Widget Message: Registering IPyWidget jupyter-matplotlib found in https://file%2B.vscode-resource.vscode-cdn.net/c%3A/Users/~/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-win32-x64/temp/scripts/56df79ef08db0a3af2549dadb3a18a89594a48162c3403c4b2a7d62eea2209f6/jupyter/nbextensions/jupyter-matplotlib/index.
18:12:46.468 [debug] creating new code watcher with matching document file:///c%3A/Users/~/Desktop/GDSFactoryHGXS/JupyterTest/Test_import.py
18:12:53.931 [debug] Handle Execution of Cells 0 for ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb
18:12:53.932 [trace] Execute Notebook ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb. Step 1
18:12:53.932 [trace] Connect to Kernel ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb. Step 2
18:12:53.932 [trace] Connected to Kernel ~\Desktop\GDSFactoryHGXS\JupyterTest\Debug01.ipynb. Step 3
18:12:53.933 [trace] executeCell 0. Step 4
18:12:53.933 [trace] Cell Index:0 sent to kernel
18:12:53.938 [trace] Start cell 0 execution @ 1730196773938 (clear output)
18:12:53.939 [debug] Kernel acknowledged execution of cell 0 @ 1730196773938
18:12:53.942 [trace] Cell 0 completed in 0.004s (start: 1730196773938, end: 1730196773942)
18:12:53.942 [trace] Cell 0 executed successfully

@luomeng007
Copy link
Author

Please could you enable logging as follows:

  • Open settings & go into Jupyter->Logging
  • Change the value to trace
  • Reload VS Code,
  • Attempt to repro the issue & then copy the output from the Jupyter output panel (use the command Jupyter: Show Output to get to the logs).

Hi, I have updated the extra information, any comment from you?

@DonJayamanne
Copy link
Contributor

Please can you try the same in Jupyter Lab application outside VS Code against the same Python environment c:\Softwares\Python 3.11.5\python.exe
Run the following in a terminal

  • Open a terminal in the folder c:\Users\luome\Desktop\GDSFactoryHGXS
  • c:\Softwares\Python 3.11.5\python.exe -m pip install jupyterlab
  • c:\Softwares\Python 3.11.5\python.exe -m jupyter lab
  • When jupyter opens , open your new notebook
  • Run the following code in a cell
%load_ext autoreload
%autoreload 2
  • Next run the following code in another cell of the same notebook
import Test_import as t

result = t.Debug()
print(result)
  • Now make changes to the test_import.py file as earlier
  • Run the cell again and verify if the changes are there

I do not think this will work,
but you can share the logs from the terminal, there might be some errors. Please share the output from the terminal.

@luomeng007
Copy link
Author

This is quite strange, it works!

Image

The log are as follow:
c:\Users\luome\Desktop\GDSFactoryHGXS>python.exe -m jupyter lab
[I 2024-11-01 16:45:52.743 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-11-01 16:45:52.747 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-11-01 16:45:52.752 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-11-01 16:45:52.758 ServerApp] notebook | extension was successfully linked.
[I 2024-11-01 16:45:53.083 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-11-01 16:45:53.112 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-11-01 16:45:53.115 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-11-01 16:45:53.116 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-11-01 16:45:53.118 LabApp] JupyterLab extension loaded from C:\Softwares\Python 3.11.5\Lib\site-packages\jupyterlab
[I 2024-11-01 16:45:53.118 LabApp] JupyterLab application directory is C:\Softwares\Python 3.11.5\share\jupyter\lab
[I 2024-11-01 16:45:53.118 LabApp] Extension Manager is 'pypi'.
[I 2024-11-01 16:45:53.367 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-11-01 16:45:53.377 ServerApp] notebook | extension was successfully loaded.
[I 2024-11-01 16:45:53.378 ServerApp] Serving notebooks from local directory: c:\Users\luome\Desktop\GDSFactoryHGXS
[I 2024-11-01 16:45:53.378 ServerApp] Jupyter Server 2.14.2 is running at:
[I 2024-11-01 16:45:53.378 ServerApp] http://localhost:8888/lab?token=e1dfe6c537a92eabc31c8f4fa7c03d1050687654e95e7dc9
[I 2024-11-01 16:45:53.378 ServerApp]     http://127.0.0.1:8888/lab?token=e1dfe6c537a92eabc31c8f4fa7c03d1050687654e95e7dc9
[I 2024-11-01 16:45:53.378 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-11-01 16:45:53.401 ServerApp]

    To access the server, open this file in a browser:
        file:///C:/Users/luome/AppData/Roaming/jupyter/runtime/jpserver-15484-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=e1dfe6c537a92eabc31c8f4fa7c03d1050687654e95e7dc9
        http://127.0.0.1:8888/lab?token=e1dfe6c537a92eabc31c8f4fa7c03d1050687654e95e7dc9
[I 2024-11-01 16:45:53.435 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[W 2024-11-01 16:45:55.547 LabApp] Could not determine jupyterlab build status without nodejs
[I 2024-11-01 16:45:56.281 ServerApp] Kernel started: 8c71a889-31bd-40be-a774-c02e78696b15
[IPKernelApp] ERROR | Exception while loading config file C:\Users\luome\.ipython\profile_default\ipython_config.py
Traceback (most recent call last):
  File "C:\Softwares\Python 3.11.5\Lib\site-packages\traitlets\config\application.py", line 915, in _load_config_files
    config = loader.load_config()
             ^^^^^^^^^^^^^^^^^^^^
  File "C:\Softwares\Python 3.11.5\Lib\site-packages\traitlets\config\loader.py", line 622, in load_config
    self._read_file_as_dict()
  File "C:\Softwares\Python 3.11.5\Lib\site-packages\traitlets\config\loader.py", line 655, in _read_file_as_dict
    exec(compile(f.read(), conf_filename, "exec"), namespace, namespace)  # noqa: S102
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\luome\.ipython\profile_default\ipython_config.py", line 1343
    ]
    ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 31-32: truncated \UXXXXXXXX escape
[I 2024-11-01 16:45:57.307 ServerApp] Connecting to kernel 8c71a889-31bd-40be-a774-c02e78696b15.
[I 2024-11-01 16:45:57.317 ServerApp] Connecting to kernel 8c71a889-31bd-40be-a774-c02e78696b15.
[I 2024-11-01 16:45:57.329 ServerApp] Connecting to kernel 8c71a889-31bd-40be-a774-c02e78696b15.
[I 2024-11-01 16:46:34.364 ServerApp] Saving file at /JupyterTest/Test_import.py
[I 2024-11-01 16:47:56.910 ServerApp] Saving file at /JupyterTest/D

@DonJayamanne
Copy link
Contributor

Please can you try in VS Code again.

@luomeng007
Copy link
Author

Please can you try in VS Code again.

In VS code, same procedure works. But this is not my problem I think. What I want is to put

"jupyter.runStartupCommands": [
   "%load_ext autoreload",
   "%autoreload 2",
]

these code inside VS code settings, I mean I do not need to run

"%load_ext autoreload",
   "%autoreload 2",

in notebook block individually..... I think we missed the topic.

@luomeng007
Copy link
Author

Please can you try in VS Code again.

Hi, any comment from your side?

@DonJayamanne
Copy link
Contributor

In VS code, same procedure works. But this is not my problem I think. What I want is to put

Got it, thats what I missed

@DonJayamanne DonJayamanne removed the info-needed Issue requires more information from poster label Dec 11, 2024
@luomeng007
Copy link
Author

Ok, hoep this can be fixed soon. You are the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel)
Projects
None yet
Development

No branches or pull requests

2 participants