For some reason when i do anything python3 related on my terminal it comes up with the error "Illegal Instruction". Why is this happening? [duplicate]
I have an old iMac running High Sierra and I use the Anaconda distribution of python 3.7. I've been using Anaconda for over 2 years and it has worked fine. I have a test code I've run over 100 times to be sure my python still works after doing something stupid on my computer. About a week ago I was trying to get a python script to run and input some bad parameters into the code. This appeared to lock up my computer and without thinking I manually restarted my computer.
Now I can't seem to get python to work no matter what I do. Before this I had run python scripts using Atom and VSCode. Both worked fine and I checked both out with my test code many times. I would also run Python from the command line and it worked fine as well. Now when I try to run a script in Atom or VSCode it doesn't work. Sometimes it gives me an "Illegal instruction: 4" message. And other times I get "No module named vpython found. Even though I installed vpython on my machine using conda install vpython
.
When I run my test code from the terminal I get an immediate return which says "Illegal instruction: 4". My test code doesn't use vpython.
I have deleted and reinstalled the Anaconda Python twice. I do not have time machine working on my computer so I'd like to fix this issue. Does anyone know why I keep getting the illegal instruction 4 when I run from the command line?
Details:
- macOS 10.13.6
-
Python:
which python3 /Users/myname/opt/anaconda3/bin/python3
I just wrote a simple script and it ran fine in the terminal. The script read in a number and printed it back out and also printed version of python it was using. The source code is:
num = int(input("Enter a number: "))
print(num)
import sys
print(sys.version)
Adding any one of these three lines to the above script causes the illegal instruction 4 output.
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
So it seems to be something due to these import commands. Although import system works fine!
Solution 1:
I found a solution but I'm not 100% sure its the whole answer. My test codes now run fine. I very carefully reloaded the Anaconda distribution for python 3.7 and i made sure to activate my virtual environment ASAP. When Anaconda is loaded, it also loads many packages. I noticed that it did not load numpy, although it had in the past. It did load something called numbpy, I think it was. Anyway, making sure my virtual environment was activated I loaded numpy for my environment by typing:
conda install -n yourenvname [package]
I also did the same for vpython. Now everything seems to work. I suppose the problem was trying to import a package that hadn't been installed properly. I'm sure I've committed the foul-up before but I don't recall ever seeing "Illegal instruction 4".