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

Discrepancies in sys.path in Kernel vs Terminal #9379

Closed
DonJayamanne opened this issue Mar 16, 2022 · 6 comments · Fixed by #9501
Closed

Discrepancies in sys.path in Kernel vs Terminal #9379

DonJayamanne opened this issue Mar 16, 2022 · 6 comments · Fixed by #9501
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debt Code quality issues notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) verification-steps-needed Steps to verify are needed for verification verified Verification succeeded

Comments

@DonJayamanne
Copy link
Contributor

Summary:

  • For non-global environments we don't need to append the user site packages (ie. the trailing paths in sys.path is not necessary).

For a conda environment:

# Kernel
python -c "import sys;print(sys.path)"
['/home/don/samples/pySamples/crap/misc',
 '/home/don/miniconda3/envs/env1/lib/python38.zip',
 '/home/don/miniconda3/envs/env1/lib/python3.8',
 '/home/don/miniconda3/envs/env1/lib/python3.8/lib-dynload',
 '',
 '/home/don/miniconda3/envs/env1/lib/python3.8/site-packages',
 '/home/don/miniconda3/envs/env1/lib/python3.8/site-packages/IPython/extensions',
 '/home/don/.ipython',
 '/home/don/.local/lib/python3.8/site-packages']
# Terminal
python -c "import sys;print(sys.path)"
['/home/don/samples/pySamples/crap/misc',
 '/home/don/miniconda3/envs/env1/lib/python38.zip',
 '/home/don/miniconda3/envs/env1/lib/python3.8',
 '/home/don/miniconda3/envs/env1/lib/python3.8/lib-dynload',
 '',
 '/home/don/.local/lib/python3.8/site-packages',
 '/home/don/miniconda3/envs/env1/lib/python3.8/site-packages',
 '/home/don/miniconda3/envs/env1/lib/python3.8/site-packages/IPython/extensions',
 '/home/don/.ipython']

For Virtual Env on windows

# Our kernel
['c:\\Development\\samples\\pySamples\\sample1', 
'C:\\Python39\\python39.zip', 
'C:\\Python39\\DLLs', 
'C:\\Python39\\lib', 
'C:\\Python39', 
'c:\\Development\\samples\\pySamples\\sample1\\.venv', 
'', 
'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages', 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\win32', 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\win32\\lib', 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\Pythonwin', 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\IPython\\extensions', 
'C:\\Users\\donja\\.ipython', 
'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages', 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32', 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32\\lib', 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\Pythonwin']

# Jupyter Notebook
['C:\\Development\\samples\\pySamples\\sample1',
 'C:\\Python39\\python39.zip',
 'C:\\Python39\\DLLs',
 'C:\\Python39\\lib',
 'C:\\Python39',
 'c:\\Development\\samples\\pySamples\\sample1\\.venv',
 '',
 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages',
 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\win32',
 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\win32\\lib',
 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\Pythonwin',
 'c:\\Development\\samples\\pySamples\\sample1\\.venv\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\donja\\.ipython']

For virtual env:

# Our kernel
['/home/don/samples/pySamples/crap/misc',
 '/home/don/.pyenv/versions/3.8.12/lib/python38.zip',
 '/home/don/.pyenv/versions/3.8.12/lib/python3.8',
 '/home/don/.pyenv/versions/3.8.12/lib/python3.8/lib-dynload',
 '',
 '/home/don/samples/pySamples/crap/.venv/lib/python3.8/site-packages',
 '/home/don/samples/pySamples/crap/.venv/lib/python3.8/site-packages/IPython/extensions',
 '/home/don/.ipython',
 '/home/don/.local/lib/python3.8/site-packages']

# Jupyter Notebook
['/home/don/samples/pySamples/crap/misc',
 '/home/don/.pyenv/versions/3.8.12/lib/python38.zip',
 '/home/don/.pyenv/versions/3.8.12/lib/python3.8',
 '/home/don/.pyenv/versions/3.8.12/lib/python3.8/lib-dynload',
 '',
 '/home/don/samples/pySamples/crap/.venv/lib/python3.8/site-packages',
 '/home/don/samples/pySamples/crap/.venv/lib/python3.8/site-packages/IPython/extensions',
 '/home/don/.ipython']

For global env

# Our Kernel
['c:\\Development\\samples\\pySamples\\sample1', 
'C:\\Python39\\python39.zip', 
'C:\\Python39\\DLLs', 
'C:\\Python39\\lib', 
'C:\\Python39', 
'', 
'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages', 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32', 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32\\lib', 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\Pythonwin', 
'C:\\Python39\\lib\\site-packages', 
'C:\\Python39\\lib\\site-packages\\win32', 
'C:\\Python39\\lib\\site-packages\\win32\\lib', 
'C:\\Python39\\lib\\site-packages\\Pythonwin']

# Jupyter Notebook
['C:\\Development\\samples\\pySamples\\sample1\\crap',
 'C:\\Python39\\python39.zip',
 'C:\\Python39\\DLLs',
 'C:\\Python39\\lib',
 'C:\\Python39',
 '',
 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages',
 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32',
 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\win32\\lib',
 'C:\\Users\\donja\\AppData\\Roaming\\Python\\Python39\\site-packages\\Pythonwin',
 'C:\\Python39\\lib\\site-packages',
 'C:\\Python39\\lib\\site-packages\\win32',
 'C:\\Python39\\lib\\site-packages\\win32\\lib',
 'C:\\Python39\\lib\\site-packages\\Pythonwin']
@DonJayamanne DonJayamanne added the bug Issue identified by VS Code Team member as probable bug label Mar 16, 2022
@DonJayamanne
Copy link
Contributor Author

This could probably explain why we're seeing other global packages in virtual environments #9164

@DonJayamanne
Copy link
Contributor Author

I.e. for non-global environment we don't need to add user site_packages into the sys.path at all.

@DonJayamanne DonJayamanne self-assigned this Mar 17, 2022
@DonJayamanne DonJayamanne added debt Code quality issues notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) and removed needs-triage labels Mar 17, 2022
@DonJayamanne DonJayamanne added this to the April 2022 milestone Mar 27, 2022
@rchiodo rchiodo added the verified Verification succeeded label Apr 28, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Apr 28, 2022

So not entirely sure what the expected behavior is here, but I get different results from the terminal and from our stuff:

Conda env:

Ours:

['d:\\Source\\Testing\\Testing_3', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\python39.zip', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\DLLs', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\lib', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest', '', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\lib\\site-packages', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\lib\\site-packages\\win32', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\lib\\site-packages\\win32\\lib', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\lib\\site-packages\\Pythonwin', 'c:\\Users\\aku91\\miniconda3\\envs\\condaEnvTest\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\aku91\\.ipython']

Terminal/Jupyter

['', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\python39.zip', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\DLLs', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\lib', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest', 'C:\\Users\\aku91\\AppData\\Roaming\\Python\\Python39\\site-packages', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\lib\\site-packages', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\lib\\site-packages\\win32', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\lib\\site-packages\\win32\\lib', 'C:\\Users\\aku91\\miniconda3\\envs\\condaenvtest\\lib\\site-packages\\Pythonwin']

Where jupyter/terminal DO have the global site-packages in the list, but we DON'T.

I believe you changed our stuff to not have it on purpose?

@rchiodo rchiodo added verification-steps-needed Steps to verify are needed for verification and removed verified Verification succeeded labels Apr 28, 2022
@joyceerhl
Copy link
Contributor

@DonJayamanne how should this be verified?

@rchiodo rchiodo reopened this May 3, 2022
@rchiodo
Copy link
Contributor

rchiodo commented May 3, 2022

Not sure what the expected behavior here is. Reopening to look at next month.

@rchiodo rchiodo removed this from the April 2022 milestone May 3, 2022
@DonJayamanne
Copy link
Contributor Author

I believe you changed our stuff to not have it on purpose?

Yes thats correct.

@rchiodo what you have here #9379 (comment) is what is expected.
Closing as verified.

@DonJayamanne DonJayamanne added the verified Verification succeeded label May 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 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 debt Code quality issues notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) verification-steps-needed Steps to verify are needed for verification verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants