I have a simple script to read a data and a model and compute score on it.
import pandas as pd
import pickle
from sklearn import metrics
from sklearn.metrics import f1_score
with open('samplemodel.pkl', 'rb') as file:
model = pickle.load(file)
testdata=pd.read_csv('testdata_l3demo.csv')
X = testdata[['bed','bath']].values.reshape(-1,2)
y = testdata['highprice'].values.reshape(-1,1)
predicted=model.predict(X)
f1score=metrics.f1_score(predicted,y)
print(f1score)
If I run the above script with python3 script.py
, it shows me this error:
ModuleNotFoundError: No module named 'pandas'
. But if I run python script.py
, it works perfectly fine.
I tried to pip list
and am able to see pandas 1.4.3
.
I am on MacOS and not in any virtual env.
This does not affect anything so far, but I would love to know why and how to fix this.
thank you
CodePudding user response:
There are 2 major versions of the Python programming language - python 2 and python 3 - you can find more information here.
Python 2 has been officially discontinued, but stays around for legacy reasons (to support software that has been built on and uses python 2). It also stays on on some OS'es as the default version of python.
Python 3 is where all the latest and greatest developments are happening.
If you do not have a specific, compelling reason to use Python 2 - you should stick with Python 3.
On Operating Systems where both Python 2 and Python 3 are installed, you can distinguish between the two versions with the 3
suffix - e.g. python3
or pip3
or ipython3
etc. In other words, pip install xx
would install a python 2 version of the package whereas a pip3 install xx
would install a python 3 version.