Skip to content

Instantly share code, notes, and snippets.

@dephiros
Last active August 11, 2025 15:43
Show Gist options
  • Save dephiros/93bdc22420e2d46e396e0cb5e417885b to your computer and use it in GitHub Desktop.
Save dephiros/93bdc22420e2d46e396e0cb5e417885b to your computer and use it in GitHub Desktop.
Debug and fix pyright Python resolution issues with UV
#!/bin/bash
echo "=== Debugging Pyright Python Resolution Issue ==="
echo ""
echo "1. Check Python environment setup:"
echo " Without direnv (shell Python):"
command -v python
python --version
python -c "import sys; print(f' Executable: {sys.executable}')"
echo ""
echo " With direnv (venv Python):"
direnv exec . which python
direnv exec . python --version
direnv exec . python -c "import sys; print(f' Executable: {sys.executable}')"
echo ""
echo "2. Check venv's base Python (created from UV):"
.venv/bin/python -c "import sys; print(f' Base prefix: {sys.base_prefix}')"
.venv/bin/python -c "import sys; print(f' Venv prefix: {sys.prefix}')"
echo ""
echo "3. Test if venv Python can import built-in modules:"
.venv/bin/python -c "
import sys
print(f' Python: {sys.executable}')
try:
import _typing
print(' ✓ _typing imported successfully')
except ImportError as e:
print(f' ✗ _typing import failed: {e}')
try:
import _functools
print(' ✓ _functools imported successfully')
except ImportError as e:
print(f' ✗ _functools import failed: {e}')
try:
import _collections
print(' ✓ _collections imported successfully')
except ImportError as e:
print(f' ✗ _collections import failed: {e}')
try:
import _io
print(' ✓ _io imported successfully')
except ImportError as e:
print(f' ✗ _io import failed: {e}')
"
echo ""
echo "4. Check UV Python installation that venv was created from:"
UV_PYTHON="$HOME/.local/share/uv/python/cpython-3.11.10-macos-aarch64-none"
echo " UV Python location: $UV_PYTHON"
if [ -d "$UV_PYTHON" ]; then
echo " UV Python exists: YES"
ls -la "$UV_PYTHON/bin/python" 2>/dev/null || ls -la "$UV_PYTHON/bin/python3" 2>/dev/null
echo ""
echo " lib-dynload contents (should have _typing.so):"
ls -la "$UV_PYTHON/lib/python3.11/lib-dynload/" | head -10
else
echo " UV Python exists: NO - This is a problem!"
fi
echo ""
echo "5. Test UV Python directly:"
if [ -f "$UV_PYTHON/bin/python" ]; then
"$UV_PYTHON/bin/python" -c "import _typing; print(' UV Python: _typing OK')" 2>&1
elif [ -f "$UV_PYTHON/bin/python3" ]; then
"$UV_PYTHON/bin/python3" -c "import _typing; print(' UV Python: _typing OK')" 2>&1
else
echo " UV Python binary not found!"
fi
echo ""
echo "6. Check for _typing.so in UV Python:"
find "$UV_PYTHON" -name "_typing*.so" 2>/dev/null
echo ""
echo "7. Check pyright configuration:"
echo " Pyright version:"
pyright --version
echo ""
echo " pyproject.toml [tool.pyright] section:"
grep -A15 "\[tool.pyright\]" pyproject.toml
echo ""
echo "8. Environment variables that might affect Python:"
echo " PYTHONPATH: ${PYTHONPATH:-not set}"
echo " PYTHONHOME: ${PYTHONHOME:-not set}"
echo " VIRTUAL_ENV: ${VIRTUAL_ENV:-not set}"
echo ""
echo "=== Summary ==="
echo "If you see '_typing import failed' in step 3, the venv Python is broken."
echo "If you see 'UV Python: _typing OK' in step 5 but step 3 fails, the venv needs recreation."
echo "If UV Python directory doesn't exist or is empty, UV needs to reinstall Python."
echo ""
echo "Clear everything and start fresh:"
echo " # Clear all UV data"
echo " rm -rf ~/.local/share/uv"
echo " rm -rf ~/.cache/uv"
echo " # Clear pyright cache"
echo " rm -rf ~/.cache/pyright-python"
echo " # Recreate everything"
echo " uv python install 3.11.10"
echo " rm -rf .venv"
echo " uv venv --python 3.11.10"
echo " uv pip sync requirements.txt"
echo ""
echo "=== End Debug Info ==="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment