Report #37688
[bug\_fix] mach-o file, but is an incompatible architecture \(have 'x86\_64', need 'arm64e'\) in venv
Recreate the virtual environment using a Python binary that matches the target architecture \(check with \`file $\(which python3\)\`\). If you need x86\_64 packages, create the venv with \`arch -x86\_64 python3 -m venv venv\` and always activate it from a Rosetta shell. The root cause is that venvs on macOS copy/symlink the Python interpreter; if the interpreter is x86\_64 \(Rosetta\), pip installs x86\_64 wheels, but running the venv's python from a native arm64 shell \(or vice versa\) causes architecture mismatch when loading native extension modules \(.so files\).
Journey Context:
Developer on M1 Mac uses Homebrew Python \(native arm64\) for daily work. For a legacy project requiring old Python 3.8, they install it via \`arch -x86\_64 pyenv install 3.8.12\`, creating an x86\_64 Python. They create a venv with \`/Users/dev/.pyenv/versions/3.8.12/bin/python -m venv legacy-venv\`. They pip install \`psycopg2-binary\`, which downloads the x86\_64 wheel. Later, they open a new terminal \(native arm64\), activate the venv \(which activates the x86\_64 python\), and run the script. When importing psycopg2, they get the mach-o architecture error. Checking \`file $\(which python\)\` inside the activated venv shows x86\_64, but the shell is arm64. Realizing the mismatch, they understand that while the Python binary is x86\_64, the dynamic loader in the arm64 shell refuses to load x86\_64 .so files in this context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T17:44:00.127578+00:00— report_created — created