Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Illegal instruction: 4" when trying to start Python with virtualenv in OS X

I've been using Python 2.7.10 in a virtualenv environment for a couple of months.

Yesterday, activating the environment went fine, but today suddently I get this cryptic error when trying to start Python from Terminal:

Illegal instruction: 4

I have made no changes to my environment (AFAIK), so I'm having a difficult time trying to come to terms with what this error is and what caused it.

Python works fine outside of this virtualenv environment. When running via /usr/local/bin it presents no problem.

like image 634
P A N Avatar asked Nov 17 '15 10:11

P A N


2 Answers

I've had this problem a number of times now. While I can't say for certain what the actual issue is, I believe it basically means that some file(s) in the virtualenv installment of Python have become corrupted.

I keep my virtual environment in a synced Dropbox folder, so that may be a large contributor to the issue.

Restoring the virtual environment from a back-up archive worked for me. Or simply reinstall an identical virtual environment.

  • First, try activating the faulty environment by cd <path/to/old_env> and source /bin/activate.
  • If it's successfully activated, cd to an accessible location on the drive and run pip freeze > requirements.txt to export a list of currently installed Python modules.
  • Delete the old environment.
  • Install a new virtual environment of the latest version of Python 2 that you have on the computer, via virtualenv <path/new_env>
  • Or, if you want to use a specific Python version, first make sure you have you have it on your drive, and then do virtualenv -p <path>. Assuming that you have downloaded the Python version with Homebrew, e.g.: virtualenv -p /usr/local/bin/python2.6 <path/new_env>
  • Activate the virtual environment via cd <path/new_env> and then do source /bin/activate.
  • Assuming that you kept a list of modules to reinstall by previously doing pip freeze > requirements.txt, cd to the folder where the text file is located and do pip install -r requirements.txt.
  • Otherwise, reinstall the modules with pip manually.
like image 55
P A N Avatar answered Oct 15 '22 21:10

P A N


I had same problem and found solution by uninstalling psycopg2 and installing older version. As I understood my comp was not supporting some commands in new version

like image 26
Rustem Kerimov Avatar answered Oct 15 '22 19:10

Rustem Kerimov