|
| 1 | +"""Debug script to test extension import.""" |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import traceback |
| 5 | + |
| 6 | +print(f"Python version: {sys.version}") |
| 7 | +print(f"Python executable: {sys.executable}") |
| 8 | +print(f"Current working directory: {os.getcwd()}") |
| 9 | +print(f"sys.path:") |
| 10 | +for p in sys.path: |
| 11 | + print(f" {p}") |
| 12 | +print() |
| 13 | + |
| 14 | +# First, check if maxminddb can be imported at all |
| 15 | +try: |
| 16 | + import maxminddb |
| 17 | + print(f"maxminddb package location: {maxminddb.__file__}") |
| 18 | + maxminddb_dir = os.path.dirname(maxminddb.__file__) |
| 19 | + print(f"maxminddb directory: {maxminddb_dir}") |
| 20 | + print() |
| 21 | + |
| 22 | + # List files in maxminddb directory |
| 23 | + print("Files in maxminddb directory:") |
| 24 | + for filename in sorted(os.listdir(maxminddb_dir)): |
| 25 | + filepath = os.path.join(maxminddb_dir, filename) |
| 26 | + size = os.path.getsize(filepath) if os.path.isfile(filepath) else "DIR" |
| 27 | + print(f" {filename:50s} {str(size):>10s}") |
| 28 | + print() |
| 29 | + |
| 30 | + # Check if there's a site-packages version |
| 31 | + site_packages_path = None |
| 32 | + for path in sys.path: |
| 33 | + if 'site-packages' in path: |
| 34 | + potential = os.path.join(path, 'maxminddb') |
| 35 | + if os.path.exists(potential): |
| 36 | + site_packages_path = potential |
| 37 | + break |
| 38 | + |
| 39 | + if site_packages_path and site_packages_path != maxminddb_dir: |
| 40 | + print(f"ALSO found maxminddb in site-packages: {site_packages_path}") |
| 41 | + print("Files in site-packages maxminddb:") |
| 42 | + for filename in sorted(os.listdir(site_packages_path)): |
| 43 | + filepath = os.path.join(site_packages_path, filename) |
| 44 | + size = os.path.getsize(filepath) if os.path.isfile(filepath) else "DIR" |
| 45 | + print(f" {filename:50s} {str(size):>10s}") |
| 46 | + print() |
| 47 | +except Exception as e: |
| 48 | + print(f"FAILED to import maxminddb: {e}") |
| 49 | + traceback.print_exc() |
| 50 | + sys.exit(1) |
| 51 | + |
| 52 | +# Now try to import the extension |
| 53 | +try: |
| 54 | + import maxminddb.extension as ext |
| 55 | + print(f"SUCCESS: Extension imported: {ext}") |
| 56 | + print(f"Extension file: {ext.__file__}") |
| 57 | + print(f"Has Reader: {hasattr(ext, 'Reader')}") |
| 58 | +except ImportError as e: |
| 59 | + print(f"FAILED: ImportError: {e}") |
| 60 | + print("\nFull traceback:") |
| 61 | + traceback.print_exc() |
| 62 | +except Exception as e: |
| 63 | + print(f"FAILED: Unexpected error: {e}") |
| 64 | + print("\nFull traceback:") |
| 65 | + traceback.print_exc() |
0 commit comments