-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_python.py
More file actions
executable file
·97 lines (76 loc) · 2.4 KB
/
check_python.py
File metadata and controls
executable file
·97 lines (76 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
"""
Python environment validation script.
Checks for required Python modules and common issues.
"""
import sys
import subprocess
import platform
def check_lzma():
"""Check if Python has lzma support."""
try:
import lzma
return True, None
except ImportError as e:
return False, str(e)
def check_required_modules():
"""Check for critical required modules."""
issues = []
# Check lzma (critical for PyTorch Lightning)
lzma_ok, lzma_error = check_lzma()
if not lzma_ok:
issues.append({
'module': 'lzma',
'error': lzma_error,
'critical': True,
'fix': get_lzma_fix_instructions()
})
return issues
def get_lzma_fix_instructions():
"""Get platform-specific fix instructions for lzma."""
system = platform.system().lower()
if system == 'darwin': # macOS
return """Fix Python lzma support on macOS:
1. Ensure xz is installed:
brew install xz
2. Rebuild Python with lzma support:
export LDFLAGS="-L$(brew --prefix xz)/lib"
export CPPFLAGS="-I$(brew --prefix xz)/include"
export PKG_CONFIG_PATH="$(brew --prefix xz)/lib/pkgconfig:$PKG_CONFIG_PATH"
pyenv install --force 3.11.6
Or run: /tmp/fix_python_lzma.sh
3. Verify: python3 -c "import lzma; print('OK')"
"""
elif system == 'linux':
return """Fix Python lzma support on Linux:
1. Install xz development libraries:
sudo apt-get install liblzma-dev # Debian/Ubuntu
sudo yum install xz-devel # RHEL/CentOS
2. Rebuild Python or reinstall Python with lzma support
"""
else:
return """Fix Python lzma support:
Rebuild Python with lzma/xz library support.
Check your Python distribution documentation for details.
"""
def main():
"""Run all checks."""
print("🔍 Checking Python environment...")
print("")
issues = check_required_modules()
if not issues:
print("✅ All checks passed!")
return 0
print("❌ Found issues:")
print("")
for issue in issues:
severity = "CRITICAL" if issue['critical'] else "WARNING"
print(f"[{severity}] Missing module: {issue['module']}")
print(f" Error: {issue['error']}")
print("")
print(" Fix instructions:")
print(issue['fix'])
print("")
return 1
if __name__ == '__main__':
sys.exit(main())