I am trying to call the following Python script from the Ubuntu terminal using the standard
python rosen.py
but it fails. I can hit F5 in idle and it works fine but it fails when called from the terminal. The code for rosen.py is as follows:
from scipy.optimize import fmin
def rosen(x):
b=sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)
print b
return b
x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
xopt = fmin(rosen, x0, xtol=1e-8)
print xopt
again, when run in idle it works fine, but when called from the terminal it says that scipy doesn’t exist…
I can run the following numpy code from the terminal or idle and it works fine:
import numpy as np
a=np.sin(1)
print a
It will print in either the terminal window or idle window depending where it was called.
Basically, how can I get the rosen.py to import SciPy and run when called from the Ubuntu terminal??
Thank you very much for the help.
It looks to me like your version of
idleis pointing at a different python implementation than the one that is first in your PATH. Try this (from the commandline — not python):and:
Are the paths the same? If not, that’s probably your problem. To fix this, depending on your system settings, you can reorder your PATH to get the correct version of python to be called, or you could create a symbolic link to the correct python implementation somewhere very early in your path.