Issue
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.
Solution
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>
andsource /bin/activate
. - If it's successfully activated,
cd
to an accessible location on the drive and runpip 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 dosource /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 dopip install -r requirements.txt
. - Otherwise, reinstall the modules with
pip
manually.
Answered By - P A N