udacity / ud120-projects

Starter project code for students taking Udacity ud120
1.62k stars 5.66k forks source link

getting str error #194

Open vinayeq opened 5 years ago

vinayeq commented 5 years ago

TypeError Traceback (most recent call last)

in () ----> 1 import outlier_removal_regression ~\outlier_removal_regression.py in () 10 11 ### load up some practice data with outliers in it ---> 12 ages = pickle.load( open("practice_outliers_ages.pkl", "r") ) 13 net_worths = pickle.load( open("practice_outliers_net_worths.pkl", "r") ) 14 TypeError: a bytes-like object is required, not 'str'
KhinePisi commented 5 years ago

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes strings instead. In pickle.load function, the parameter "r" should be replaced with "rb". like this , ages = pickle.load( open("practice_outliers_ages.pkl", "rb") ) net_worths = pickle.load( open("practice_outliers_net_worths.pkl", "rb") )

xudong963 commented 5 years ago

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes strings instead. In pickle.load function, the parameter "r" should be replaced with "rb". like this , ages = pickle.load( open("practice_outliers_ages.pkl", "rb") ) net_worths = pickle.load( open("practice_outliers_net_worths.pkl", "rb") )

then a issues will happen: UnpicklingError: the STRING opcode argument must be quoted

Shinshan1930 commented 4 years ago

No directory found word_data_unix.pkl File "F:/github/ud120-projects/decision_tree/dt_author_id.py", line 20, in features_train, features_test, labels_train, labels_test = preprocess() File "F:\github\ud120-projects\decision_tree\email_preprocess.py", line 36, in preprocess words_file_handler = open(words_file, "rb") FileNotFoundError: [Errno 2] No such file or directory: '../tools/word_data_unix.pkl'

Process finished with exit code 1

waiyankyaw961999 commented 4 years ago

I got the same issues saying File "nb_author_id.py", line 10, in

features_train, features_test, labels_train, labels_test = preprocess() File "C:\Users\Wai Yan Kyaw\PycharmProjects\AWS Machine Learning Foundation\email_preprocess.py", l ine 35, in preprocess word_data = pickle.load(f, encoding='latin1') _pickle.UnpicklingError: the STRING opcode argument must be quoted
jaimep01 commented 4 years ago

Hello every1 in Win10 this fixed it: Remember when openning the file as well it has to be read as bytes:

authors_file_handler = open(authors_file, "rb")
words_file_handler = open(words_file, "rb")

PowerShell: $path = "\word_data.pkl" (Get-Content $path -Raw).Replace("`r`n","`n") | Set-Content $path -Force

(add you whole path to avoid issues)

fadimaximos commented 2 years ago

This is for Win10 My solution was just to add the whole path from my PC to the joblib.load command. Remember to change / to \\