situation
I created a new Python project with pixi venv.
I have this isolated venv, including Python.
I installedpandasetc.
I didn't installplotlyetc.I have Python installed globally.
The global Python environment hasplotlyinstalled.
problem
Now I open the project in VS Code.
If I try to import
plotly.
It won't show any error.
If I click into it, it goes to the global Python env site-packages.Even If I try to import
pandas.
Same thing happens.
desire
I want VS Code to truly isolate the venv.
Stop it from importing from the global Python site-packages.
Just show an error if that happens in my code.Note: I need an visible error in the IDE, not just when running in terminal.
attempts
- I tried with
PYTHONNOUSERSITE=1,- won't work for VS Code IDE
- only works in terminal (this is not enough)
include-system-site-packages = falsedoesn't exist for pixi.
compare
- if I create a project with
.venv, no such problem, it's truly isolated, and VS Code will show an error when importing a package not in venv (regardless of its in global Python env site-packages or not). - if I create a project with
.conda, some project has no such problem, (the base env), but others seems have the same problem - if I create a project with
.pixi, have the problem
diagnostics
To show where they are imported:
import sys
import os
# Print the executable python thinks it's running
print("--- Python Executable ---")
print(sys.executable)
print("-" * 25)
# Print all the paths python will search for modules
print("\n--- Module Search Paths (sys.path) ---")
for path in sys.path:
print(path)
print("-" * 25)
# Check if the PYTHONPATH variable is set
print("\n--- PYTHONPATH Environment Variable ---")
py_path = os.environ.get('PYTHONPATH')
if py_path:
print(py_path.replace(':', '\n')) # Use ';' for Windows if needed
else:
print("PYTHONPATH is not set.")
print("-" * 25)
# Try the import and see where it comes from
try:
import pandas
print("\n--- 'pandas' was found here: ---")
print(pandas.__file__)
except ImportError:
print("\n--- 'pandas' could not be imported. ---")
try:
import plotly
print("\n--- 'plotly' was found here: ---")
print(plotly.__file__)
except ImportError:
print("\n--- 'plotly' could not be imported. ---")
try:
import torch
print("\n--- 'torch' was found here: ---")
print(torch.__file__)
except ImportError:
print("\n--- 'torch' could not be imported. ---")
Output:
D:\usp\uhpsj\study\build_llm_wsp\build_llm>D:/usp/uhpsj/study/build_llm_wsp/build_llm/.pixi/envs/default/python.exe d:/usp/uhpsj/study/build_llm_wsp/build_llm/src/build_llm_demo/_demo/d2.py
--- Python Executable ---
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\python.exe
-------------------------
--- Module Search Paths (sys.path) ---
d:\usp\uhpsj\study\build_llm_wsp\build_llm\src\build_llm_demo\_demo
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\python311.zip
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\DLLs
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\Lib
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default
C:\Users\nshln\AppData\Roaming\Python\Python311\site-packages
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\Lib\site-packages
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\Lib\site-packages\win32
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\Lib\site-packages\win32\lib
D:\usp\uhpsj\study\build_llm_wsp\build_llm\.pixi\envs\default\Lib\site-packages\Pythonwin
-------------------------
--- PYTHONPATH Environment Variable ---
PYTHONPATH is not set.
-------------------------
--- 'pandas' was found here: ---
C:\Users\nshln\AppData\Roaming\Python\Python311\site-packages\pandas\__init__.py
--- 'plotly' was found here: ---
C:\Users\nshln\AppData\Roaming\Python\Python311\site-packages\plotly\__init__.py
--- 'torch' was found here: ---
C:\Users\nshln\AppData\Roaming\Python\Python311\site-packages\torch\__init__.py
pixi.toml packages
[workspace]
authors = ["norlz <[email protected]>"]
channels = ["conda-forge"]
name = "build-llm-demo"
platforms = ["win-64"]
version = "0.1.0"
[tasks]
[system-requirements]
cuda = "12.0"
[dependencies]
python = "3.11.*"
pandas = "<=2.1.4"
pydantic-settings = ">=2.9.1,<3"
ruff = ">=0.12.0,<0.13"
pyright = ">=1.1.402,<2"
pytest = ">=8.4.1,<9"
pytorch-gpu = "*"
cuda-version = "12.6.*"
[pypi-dependencies]
fastapi = { version = ">=0.115.13, <0.116", extras = ["standard"] }
uvicorn = { version = ">=0.34.3, <0.35", extras = ["standard"] }
gunicorn = ">=23.0.0, <24"


python.exebinary too. I tried to switch the .exe file, seems getting different results. Not sure.