"Invalid instruction: 4" when trying to start Python with virtualenv on OS X

I have been using Python 2.7.10 in virtualenv environment for several months.

Yesterday, the environment turned on normally, but today I am sadly getting this cryptic error when trying to start Python from the terminal:

Illegal instruction: 4

I have not made any changes to my environment (AFAIK), so I have a difficult time trying to understand what this error is and what caused it.

Python works fine outside of this virtualenv environment. When launched via /usr/local/bin this does not cause problems.

+5
source share
2 answers

I have had this problem several times. Although I cannot say for sure what the actual problem is, I believe that this basically means that some files in the python virtualenv package have become corrupted.

I keep my virtual environment in a synchronized Dropbox folder, so this can be a big cause of the problem.

Restoring a virtual environment from a backup archive worked for me. Or just reinstall the identical virtual environment.

  • First try activating the failed environment using cd <path/to/old_env> and source /bin/activate .
  • If it is successfully activated, cd to an accessible place on the disk and run pip freeze > requirements.txt to export the list of installed Python modules.
  • Remove old medium.
  • Install the new virtual environment of the latest version of Python 2 that you use on your computer via virtualenv <path/new_env>
  • Or, if you want to use a specific version of Python, first make sure you have it on your disk, and then run virtualenv -p <path> . Assuming you downloaded the Python version using Homebrew, for example: virtualenv -p /usr/local/bin/python2.6 <path/new_env>
  • Activate the virtual environment through cd <path/new_env> , and then do source /bin/activate .
  • Assuming that you saved the list of modules for reinstallation by first doing pip freeze > requirements.txt , cd in the folder where the text file is located, and doing pip install -r requirements.txt .
  • Otherwise, reinstall the modules using pip manually.
+1
source

I had the same problem and the solution found by uninstalling psycopg2 and installing an older version. Since I realized that my computer did not support some commands in the new version

+1
source

Source: https://habr.com/ru/post/1236133/


All Articles