Display Python data files in VSCode.
- Numpy Files:
.npz
.npy
- Pickle Files:
.pkl
.pck
.pickle
.pkl.gz
- PyTorch Files:
.pth
.pt
.ckpt
- Install the extension from VS Code marketplace
- Open any supported data file in VS Code
- The file will automatically display with formatted content
📌 Python interpreter is required. Add Python to your system PATH or configure a custom Python path in the extension settings.
vscode-pydata-viewer.pythonPath
: Path to Python interpreter (default:"default"
)vscode-pydata-viewer.scriptPath
: Path to custom processing script (default:"default"
)
- Open VS Code Settings (
Cmd+,
orCtrl+,
) - Search for "pydata viewer"
- Set Python Path:
- System Python: Leave as
"default"
- Virtual Environment:
/path/to/venv/bin/python
- Conda Environment:
/path/to/conda/envs/myenv/bin/python
- System Python: Leave as
If your pickle files contain custom classes from your project, you have these options:
Create a custom script that imports your modules:
import sys
import pickle
from pathlib import Path
# Add your project to Python path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
# Import your custom classes
from my_project.models import MyCustomClass
def process_pickle_file(file_path):
with open(file_path, 'rb') as f:
data = pickle.load(f)
print(f"<b>Data:</b> {data}")
if __name__ == "__main__":
file_type = int(sys.argv[1])
file_path = sys.argv[2]
if file_type == 1: # Pickle file
process_pickle_file(file_path)
Then set the script path in VS Code settings:
{
"vscode-pydata-viewer.scriptPath": "/path/to/your/custom_script.py"
}
Configure the extension to use your project's Python environment:
{
"vscode-pydata-viewer.pythonPath": "/path/to/your/project/venv/bin/python"
}
For project-specific configuration, create .vscode/settings.json
:
{
"vscode-pydata-viewer.pythonPath": "${workspaceFolder}/venv/bin/python",
"vscode-pydata-viewer.scriptPath": "${workspaceFolder}/scripts/custom_reader.py"
}
"No module named 'your_module'" Error
- Use a custom script with proper imports
- Set Python path to your project environment
- Ensure your virtual environment contains required dependencies
"Python not found" Error
- Check Python installation
- Set full path to Python executable in settings
- Restart VS Code after changing settings
Simply open any .npy
, .pkl
, or .pth
file in VS Code.
import pickle
class MyClass:
def __init__(self, value):
self.value = value
data = MyClass(42)
with open('data.pkl', 'wb') as f:
pickle.dump(data, f)
Please refer to CHANGELOG.md.
If you don't have Python available but need to view numpy files, try vscode-numpy-viewer.