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

Incorrect PYTHONPATH variable with .env file with relative paths #5061

Closed
Tracked by #6188 ...
secure-mail-documentation-project opened this issue Mar 7, 2021 · 12 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) verified Verification succeeded
Milestone

Comments

@secure-mail-documentation-project
Copy link

secure-mail-documentation-project commented Mar 7, 2021

Issue Type: Bug

The jupyter extension sets the PYTHONPATH variable incorrectly when a .env file contains relative path definitions.

To reproduce:

  • On Windows 10
  • vscode project base in C:\Users\My User\Documents\vscode_test_project
  • .env file in above direcory with the content PYTHONPATH=./some-library
  • python file subdir\test.py in above directory that is empty except for the line # %% opened in editor
  • Click on "Run Cell"
  • Jupyter opens
  • in jupyter notebook execute import sys; sys.path

Expected result:

['c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles\\.does-not-exist',
 'C:\\Users\\My User\\Documents\\vscode_test_project\\some-library',
 'c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles',
 'c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles\\lib\\python',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\python39.zip',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\DLLs',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env',
 '',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\Pythonwin',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\My User\\.ipython']

Actual result:

['c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles\\.does-not-exist',
 'C:\\Program Files\\Microsoft VS Code\\some-library',
 'c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles',
 'c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles\\lib\\python',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\python39.zip',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\DLLs',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env',
 '',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\Pythonwin',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\My User\\.ipython']

Note the invalid value of the second line containing the path for some-library. This should always be relative to the location of the location of the .env file.

Also of concern to me seems to be the first line that seems to contain part of an error message with .does-not-exist.

Extension version: 2021.2.603412351
VS Code version: Code 1.53.2 (622cb03f7e070a9670c94bae1a45d78d7181fbd4, 2021-02-11T11:48:04.245Z)
OS version: Windows_NT x64 10.0.18363

System Info
Item Value
CPUs Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz (4 x 2295)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 7.88GB (2.18GB free)
Process Argv C:\Users\My User\Documents\vscode_test_project --crash-reporter-id 52935532-1f43-4f4e-bbec-b6ee4da772c6
Screen Reader no
VM 0%
@secure-mail-documentation-project secure-mail-documentation-project added the bug Issue identified by VS Code Team member as probable bug label Mar 7, 2021
@secure-mail-documentation-project
Copy link
Author

secure-mail-documentation-project commented Mar 7, 2021

One observation that might help with debugging this issue:

Playing with the .env file I discovered that the problem can be partially fixed by setting a worspaceFolder environment variable in the .env file manually. That fixes the first line containing the remnant of an error message, the second line is however still expanded relative to the python file used to start the notebook rather than relative to the .env file.

Content of .env:

workspaceFolder=C:\Users\My User\Documents\vscode_test_project
PYTHONPATH=./some-library

Output of import sys; sys.path:

['c:\\Users\\My User\\Documents\\vscode_test_project',
 'c:\\Users\\My User\\Documents\\vscode_test_project\\subdir',
 'c:\\Users\\My User\\Documents\\vscode_test_project\\subdir\\some-library',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\python39.zip',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\DLLs',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env',
 '',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\Pythonwin',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\My User\\.ipython']

@IanMatthewHuff IanMatthewHuff self-assigned this Mar 9, 2021
@IanMatthewHuff
Copy link
Member

I'm looking at this right now (though I am on Mac and not windows) and I don't see the same issue that you are seeing:
image
Let me poke around a bit more here quick.

@IanMatthewHuff
Copy link
Member

Do I have your file layout correct? I also tried this with the subdir and that is also working.

vscode_test_project (.env file in here)
vscode_test_project/subdir (python file with cell marker here)

@secure-mail-documentation-project
Copy link
Author

@IanMatthewHuff Thanks for looking into this. Yes your directory structure is correct. See my attached screenshots.

You seem to be using linux for reproducing this. I think this might be a windows-specific problem. My second post indicates that there are problems with variable substitution on windows. I.e. why else would adding a workspaceFolder environment variable affect the paths.

Please let me know if there is anything I can do to help you debug this.

Alternative 1: simple .env file
image

image

Alternative 1: .env file with workspaceFolder environment variable
image
image

@secure-mail-documentation-project
Copy link
Author

Another thought: could part of the issue be that my project path contains a space?

@secure-mail-documentation-project
Copy link
Author

Another thought: could part of the issue be that my project path contains a space?

Just realized I can test this myself of course. I move the vscode_test_project directory to the root of an external harddrive. This got rid of the space in the project path. - No improvement at all from what I can see.

image

@IanMatthewHuff
Copy link
Member

@secure-mail-documentation-project Sorry about this being hard to work through, without having the issue on my box it's a bit hard to debug.

This isn't a full fix but as a possible workaround, we have a setting to specifically run python commands at the start of any notebook or interactive window session. If you have python code to manually add something into sys.path you could put it in here and that should run that code for any interactive sessions that you start. The setting is Jupyter: Run Startup Commands.

Currently I'm looking at all the info on configuring .env files here:
https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file

One thing to try. With just the PYTHONPATH specified instead of printing out sys.path could you instead import os and print os.environ? I'd like to see what the PYTHONPATH looks like there before it gets added to the sys.path.

@secure-mail-documentation-project
Copy link
Author

secure-mail-documentation-project commented Mar 10, 2021

@secure-mail-documentation-project Sorry about this being hard to work through, without having the issue on my box it's a bit hard to debug.

One thing to try. With just the PYTHONPATH specified instead of printing out sys.path could you instead import os and print os.environ? I'd like to see what the PYTHONPATH looks like there before it gets added to the sys.path.

No problem. I have some self-interest that this get's fixed. I am happy to help debug it.

Output of import os; os.environ:

environ{'ALLUSERSPROFILE': 'C:\\ProgramData',
        'APPDATA': 'C:\\Users\\My User\\AppData\\Roaming',
        'APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL': 'true',
        'CHROME_CRASHPAD_PIPE_NAME': '\\\\.\\pipe\\crashpad_16488_COLSEMPABNJOSNJN',
        'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files',
        'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files',
        'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files',
        'COMPUTERNAME': 'MYCOMPUTER',
        'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe',
        'CONDA_DEFAULT_ENV': 'vscode_test_env',
        'CONDA_EXE': 'C:\\ProgramData\\Miniconda3\\Scripts\\conda.exe',
        'CONDA_PREFIX': 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env',
        'CONDA_PREFIX_1': 'C:\\ProgramData\\Miniconda3',
        'CONDA_PROMPT_MODIFIER': '(vscode_test_env) ',
        'CONDA_PYTHON_EXE': 'C:\\ProgramData\\Miniconda3\\python.exe',
        'CONDA_SHLVL': '2',
        'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData',
        'ELECTRON_RUN_AS_NODE': '1',
        'HOMEDRIVE': 'C:',
        'HOMEPATH': '\\Users\\My User',
        'LOCALAPPDATA': 'C:\\Users\\My User\\AppData\\Local',
        'LOGONSERVER': '\\\\MYCOMPUTER',
        'NUMBER_OF_PROCESSORS': '4',
        'ONEDRIVE': 'C:\\Users\\My User\\OneDrive',
        'ORIGINAL_XDG_CURRENT_DESKTOP': 'undefined',
        'OS': 'Windows_NT',
        'PATH': 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env;C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\Library\\mingw-w64\\bin;C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\Library\\usr\\bin;C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\Library\\bin;C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\Scripts;C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\bin;C:\\ProgramData\\Miniconda3\\condabin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0;C:\\WINDOWS\\System32\\OpenSSH;C:\\Program Files (x86)\\Common Files\\Acronis\\VirtualFile;C:\\Program Files (x86)\\Common Files\\Acronis\\VirtualFile64;C:\\Program Files (x86)\\Common Files\\Acronis\\FileProtector;C:\\Program Files (x86)\\Common Files\\Acronis\\FileProtector64;C:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI;C:\\Program Files\\Intel\\WiFi\\bin;C:\\Program Files\\Common Files\\Intel\\WirelessCommon;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\nodejs;C:\\Users\\My User\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\My User\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\My User\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\My User\\AppData\\Roaming\\npm',
        'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
        'PROCESSOR_ARCHITECTURE': 'AMD64',
        'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 61 Stepping 4, GenuineIntel',
        'PROCESSOR_LEVEL': '6',
        'PROCESSOR_REVISION': '3d04',
        'PROGRAMDATA': 'C:\\ProgramData',
        'PROGRAMFILES': 'C:\\Program Files',
        'PROGRAMFILES(X86)': 'C:\\Program Files (x86)',
        'PROGRAMW6432': 'C:\\Program Files',
        'PROMPT': '(vscode_test_env) $P$G',
        'PSMODULEPATH': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules',
        'PUBLIC': 'C:\\Users\\Public',
        'PYTHONIOENCODING': 'utf-8',
        'PYTHONPATH': '.\\some-library;c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles;c:\\Users\\My User\\.vscode\\extensions\\ms-toolsai.jupyter-2021.2.603412351\\pythonFiles\\lib\\python',
        'PYTHONUNBUFFERED': '1',
        'PYTHONWARNINGS': 'ignore',
        'SESSIONNAME': 'Console',
        'SYSTEMDRIVE': 'C:',
        'SYSTEMROOT': 'C:\\WINDOWS',
        'TEMP': 'C:\\Users\\My User\\AppData\\Local\\Temp',
        'TMP': 'C:\\Users\\My User\\AppData\\Local\\Temp',
        'USERDOMAIN': 'MYCOMPUTER',
        'USERDOMAIN_ROAMINGPROFILE': 'MYCOMPUTER',
        'USERNAME': 'My User',
        'USERPROFILE': 'C:\\Users\\My User',
        'VS140COMNTOOLS': 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\',
        'VS2019INSTALLDIR': 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools',
        'VSCODE_AMD_ENTRYPOINT': 'vs/workbench/services/extensions/node/extensionHostProcess',
        'VSCODE_CWD': 'C:\\WINDOWS\\system32',
        'VSCODE_HANDLES_UNCAUGHT_ERRORS': 'true',
        'VSCODE_IPC_HOOK': '\\\\.\\pipe\\9baa9e15493b51ce2f3ae2619e4b305b-1.53.2-main-sock',
        'VSCODE_IPC_HOOK_EXTHOST': '\\\\.\\pipe\\vscode-ipc-ec9e04af-1898-4512-8e39-7df5223d50c4-sock',
        'VSCODE_LOG_NATIVE': 'false',
        'VSCODE_LOG_STACK': 'false',
        'VSCODE_NLS_CONFIG': '{"locale":"en-gb","availableLanguages":{},"_languagePackSupport":true}',
        'VSCODE_NODE_CACHED_DATA_DIR': 'C:\\Users\\My User\\AppData\\Roaming\\Code\\CachedData\\622cb03f7e070a9670c94bae1a45d78d7181fbd4',
        'VSCODE_PID': '16488',
        'VSCODE_PIPE_LOGGING': 'true',
        'VSCODE_VERBOSE_LOGGING': 'true',
        'VTUNE_PROFILER_2020_DIR': 'C:\\Program Files (x86)\\IntelSWTools\\VTune Profiler 2020\\',
        'WINDIR': 'C:\\WINDOWS',
        'JPY_INTERRUPT_EVENT': '584',
        'IPY_INTERRUPT_EVENT': '584',
        'JPY_PARENT_PID': '504',
        'TERM': 'xterm-color',
        'CLICOLOR': '1',
        'PAGER': 'cat',
        'GIT_PAGER': 'cat',
        'MPLBACKEND': 'module://ipykernel.pylab.backend_inline'}

The .env-file used for the above output was:

PYTHONPATH=./some-library

@secure-mail-documentation-project
Copy link
Author

@IanMatthewHuff Looking at the PYTHONPATH environment variable I noticed my path separator was different from the others: / instead of \. I changed it to the windows standard but that made no difference.

I did notice a curious effect however to do with changing the .env file in a running vscode session:

  1. Start vscode with .env containing: PYTHONPATH=./some-library
  2. Start interactive window
  3. sys.path is mangled
  4. Close interactive window
  5. Start interactive window again
  6. sys.path is still mangled

If one however modifies .env during a running vscode session, paths are almost correct:

  1. Start vscode with .env containing: PYTHONPATH=./some-library
  2. Start interactive window
  3. sys.path is mangled
  4. Close interactive window
  5. Change .env to read PYTHONPATH=.\some-library
  6. Start interactive window again
  7. sys.path now are almost correct:

Output of sys.path:

['c:\\Users\\My User\\Documents\\vscode_test_project',
 'c:\\Users\\My User\\Documents\\vscode_test_project\\subdir',
 'c:\\Users\\My User\\Documents\\vscode_test_project\\subdir\\some-library',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\python38.zip',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\DLLs',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env',
 '',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\win32\\lib',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\Pythonwin',
 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\My User\\.ipython']

Output of os.environ:

environ{'ALLUSERSPROFILE': 'C:\\ProgramData',
        'APPDATA': 'C:\\Users\\My User\\AppData\\Roaming',
        'APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL': 'true',
        'CHROME_CRASHPAD_PIPE_NAME': '\\\\.\\pipe\\crashpad_9504_VWTKTHKGSDTAXUFA',
        'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files',
        'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files',
        'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files',
        'COMPUTERNAME': 'MYCOMPUTER',
        'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe',
        'CONDA_DEFAULT_ENV': 'vscode_test_env',
        'CONDA_EXE': 'C:\\ProgramData\\Miniconda3\\Scripts\\conda.exe',
        'CONDA_PREFIX': 'C:\\ProgramData\\Miniconda3\\envs\\vscode_test_env',
        'CONDA_PREFIX_1': 'C:\\ProgramData\\Miniconda3',
        'CONDA_PROMPT_MODIFIER': '(vscode_test_env) ',
        'CONDA_PYTHON_EXE': 'C:\\ProgramData\\Miniconda3\\python.exe',
        'CONDA_SHLVL': '2',
        'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData',
        'ELECTRON_RUN_AS_NODE': '1',
        'HOMEDRIVE': 'C:',
        'HOMEPATH': '\\Users\\My User',
        'LOCALAPPDATA': 'C:\\Users\\My User\\AppData\\Local',
        'LOGONSERVER': '\\\\MYCOMPUTER',
        'NUMBER_OF_PROCESSORS': '4',
        'ONEDRIVE': 'C:\\Users\\My User\\OneDrive',
        'ORIGINAL_XDG_CURRENT_DESKTOP': 'undefined',
        'OS': 'Windows_NT',
        'PATH': 'C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Common Files\\Acronis\\VirtualFile\\;C:\\Program Files (x86)\\Common Files\\Acronis\\VirtualFile64\\;C:\\Program Files (x86)\\Common Files\\Acronis\\FileProtector\\;C:\\Program Files (x86)\\Common Files\\Acronis\\FileProtector64\\;C:\\Program Files (x86)\\Common Files\\Acronis\\SnapAPI\\;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\nodejs\\;C:\\Users\\My User\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\My User\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\My User\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\My User\\AppData\\Roaming\\npm',
        'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
        'PROCESSOR_ARCHITECTURE': 'AMD64',
        'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 61 Stepping 4, GenuineIntel',
        'PROCESSOR_LEVEL': '6',
        'PROCESSOR_REVISION': '3d04',
        'PROGRAMDATA': 'C:\\ProgramData',
        'PROGRAMFILES': 'C:\\Program Files',
        'PROGRAMFILES(X86)': 'C:\\Program Files (x86)',
        'PROGRAMW6432': 'C:\\Program Files',
        'PROMPT': '(vscode_test_env) $P$G',
        'PSMODULEPATH': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules',
        'PUBLIC': 'C:\\Users\\Public',
        'PYTHONIOENCODING': 'utf-8',
        'PYTHONPATH': '.\\some-library',
        'PYTHONUNBUFFERED': '1',
        'PYTHONWARNINGS': 'ignore',
        'SESSIONNAME': 'Console',
        'SYSTEMDRIVE': 'C:',
        'SYSTEMROOT': 'C:\\WINDOWS',
        'TEMP': 'C:\\Users\\My User\\AppData\\Local\\Temp',
        'TMP': 'C:\\Users\\My User\\AppData\\Local\\Temp',
        'USERDOMAIN': 'MYCOMPUTER',
        'USERDOMAIN_ROAMINGPROFILE': 'MYCOMPUTER',
        'USERNAME': 'My User',
        'USERPROFILE': 'C:\\Users\\My User',
        'VS140COMNTOOLS': 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\',
        'VS2019INSTALLDIR': 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools',
        'VSCODE_AMD_ENTRYPOINT': 'vs/workbench/services/extensions/node/extensionHostProcess',
        'VSCODE_CWD': 'C:\\WINDOWS\\system32',
        'VSCODE_HANDLES_UNCAUGHT_ERRORS': 'true',
        'VSCODE_IPC_HOOK': '\\\\.\\pipe\\9baa9e15493b51ce2f3ae2619e4b305b-1.53.2-main-sock',
        'VSCODE_IPC_HOOK_EXTHOST': '\\\\.\\pipe\\vscode-ipc-686b82be-30de-4230-a63d-64a4a1fcf4a2-sock',
        'VSCODE_LOG_NATIVE': 'false',
        'VSCODE_LOG_STACK': 'false',
        'VSCODE_NLS_CONFIG': '{"locale":"en-gb","availableLanguages":{},"_languagePackSupport":true}',
        'VSCODE_NODE_CACHED_DATA_DIR': 'C:\\Users\\My User\\AppData\\Roaming\\Code\\CachedData\\622cb03f7e070a9670c94bae1a45d78d7181fbd4',
        'VSCODE_PID': '9504',
        'VSCODE_PIPE_LOGGING': 'true',
        'VSCODE_VERBOSE_LOGGING': 'true',
        'VTUNE_PROFILER_2020_DIR': 'C:\\Program Files (x86)\\IntelSWTools\\VTune Profiler 2020\\',
        'WINDIR': 'C:\\WINDOWS',
        'JPY_INTERRUPT_EVENT': '616',
        'IPY_INTERRUPT_EVENT': '616',
        'JPY_PARENT_PID': '628',
        'TERM': 'xterm-color',
        'CLICOLOR': '1',
        'PAGER': 'cat',
        'GIT_PAGER': 'cat',
        'MPLBACKEND': 'module://ipykernel.pylab.backend_inline'}

Further observations:

  • After changing .env once one can change it back to its original content and sys.path remains OK.
  • It does not matter how one changes .env at all. What matters is only that .env gets changed once duing a running vscode session.

It would appear that the .env-file watcher is running some crucial action when the file is changed that does not get run at a normal jupyter startup. In fact, the PYTHONPATH environment variable has less content after .env was changed once than if it was never changed...

On a sour note: the question of what relative PYTHONPATH definitions resolve to is unaffected by this. They are still relative to the directory of the file from which the interactive window was started rather than relative to the location of the .env-file.

@greazer greazer added the info-needed Issue requires more information from poster label Mar 11, 2021
@secure-mail-documentation-project
Copy link
Author

@greazer I just saw, that you added 'info-needed'. Could you please explain what you need to proceed? As far as I am aware, I have provided all info requested by @IanMatthewHuff. Did I misunderstand something? I am more than happy to help debugging this.

@greazer greazer added this to the July 2021 Release milestone Jun 5, 2021
@greazer greazer removed the info-needed Issue requires more information from poster label Jun 6, 2021
@greazer greazer modified the milestones: July 2021, August 2021 Jul 30, 2021
@greazer greazer added the notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) label Aug 2, 2021
@greazer greazer modified the milestones: August 2021, old August 2021 Aug 9, 2021
@huweiATgithub
Copy link

In my case, the .env file doesn't load at all for a .env file as simple as,

TEST_VAR=123456

then check with,

import os
print(os.getenv("TEST_VAR"))

@DonJayamanne DonJayamanne self-assigned this Feb 14, 2022
@DonJayamanne
Copy link
Contributor

I've managed to identify the cause of the issue, when using non-conda issues we dont use the env variables at all.

@DonJayamanne DonJayamanne added this to the February 2022 milestone Feb 16, 2022
@roblourens roblourens added the verified Verification succeeded label Feb 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants