$PYTHONPATH in notebook is different than in terminal
See original GitHub issueEnvironment data
- VS Code version: 1.65.2
- Jupyter Extension version (available under the Extensions sidebar): v2022.2.1030672458
- Python Extension version (available under the Extensions sidebar): v2022.2.1924087327
- OS (Windows | Mac | Linux distro) and version: Linux
- Python and/or Anaconda version: Python 3.9.10
- Type of virtual environment used: conda
- Jupyter server running: Local
Expected behaviour
$PYTHONPATH should be the same between a notebook and the integrated terminal.
Actual behaviour
After restarting vscode and opening a fresh jupyter notebook, when I run
%%bash
echo $PYTHONPATH
in a notebook cell, the variable value is different than when I run the same command in the integrated terminal
echo $PYTHONPATH
Furthermore, I opened the notebook in JupyterLab and ran the cell and the $PYTHONPATH variable matches the value of the integrated terminal.
Summary: $PYTHONPATH variable matches between terminal and JupyterLab, but not in the vscode notebook.
Steps to reproduce:
Sorry, I’m not sure how to reproduce this.
I did change the value of the PYTHONPATH variable a few days ago. Is it possible that vscode notebook is using a cached value of PYTHONPATH that needs to be reset?
Thanks for any help you can give.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
sys.path different in Jupyter and Python - how to import own ...
Here is what I do on my projects in jupyter notebook, import sys sys.path.append("../") # go to parent dir from customFunctions import *....
Read more >Sys.path is different than terminal and ipython and ...
Hi,. I am running jupyter notebook within a python 3.9.12 conda environment. I have a project with the following structure
Read more >Settings Reference for Python - Visual Studio Code
Specifies whether to activate the currently open terminal when the Python extension is activated, using the virtual environment selected. logging.level, error ...
Read more >Finding your Anaconda Python interpreter path
Open a terminal window. · If you want the location of a Python interpreter for a conda environment other than the root conda...
Read more >Set up a working environment | DataSpell Documentation
To execute notebooks or Python code in DataSpell, you need to configure ... You can select any other Python environment on your machine...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That explains it, when we launch the kernels, the extension does not read bashrc files. In fact we don’t read any shell scripts the user may have configured. To load variables from a shell script we’d need to initialize a shell, and this has a number of problems associated with that (it can be very slow, sometimes even slow down VS Code completely and cause perf issues).
I’m sorry, however at this stage I don’t see a way around this, except for adding the PYTHONPATH path value into your settings.json as follows:
PYTHONPATH=xyz
)Optionally, if you would like this to apply to all workspace folders, then please do file an issue in this repo and we’ll look into that. Basically today you need a .env file per workspace, if you’d like to share that across all workspaces we don’t support that, but should be easy to do (as the Python extension supports that).
Closing this issue, as we’re not going to support reading the shell scripts and the work around is to use a .env file.
Thanks for your help. I’ll make the necessary changes.