Giter Site home page Giter Site logo

Comments (68)

ShengKungYi avatar ShengKungYi commented on August 16, 2024 24

You should be running the script directly from the naive_bayes folder. This is because email_preprocess.py is found in the tools folder, thus the need for the statement made on the immediately preceding line (16).

from ud120-projects.

tzenga avatar tzenga commented on August 16, 2024 4

If anyone is having the issue when trying to run the naive bayes project because of cross_validation you need to change all references of cross_validation to model_selection. The cross_validation module has been changed to model_selection so the email_preprocess.py will not run.

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024 3

You might be interested in installing the Anaconda distribution of Python since it's got a lot of common data science packages included, and it's fairly easy to update (using conda instead of pip). If you're on a Windows machine, this page is an unofficial repository of binaries that you might have better luck with installation.

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024 2

I noticed that you are calling the script from the base folder. You should run the script from the "naive_bayes" folder in order for the script to find the "email_preprocess.py" script for importing. (The script is in the "tools" folder, and so your working directory needs to be "naive_bayes" in order to add "tools" to the path.)

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024 2

Hi @P13CE , can you make sure that you are running the command from the naive_bayes folder? It needs to be your working directory in order for the imported functions to be found properly; in this case, the expression that you'll use to run the file will just be python nb_author_id.py.

from ud120-projects.

SQuintin avatar SQuintin commented on August 16, 2024 2

I'm stuck on this. I read every post here probably a dozen times, and I still have no idea how to solve this "closed" issue.

Considering that this code is made for students in a learning program, it's pretty obtuse for the author to close the issue without providing a plain-text explanation of how to fix the problem. "You should be running the script directly from the naive_bayes folder" is a meaningless sentence that doesn't explain the problem or the solution. It's pretty naïve of the author to consider that sentence as a solution considering the audience.

I'm opening the file directly from the naïve_bayes folder, which I will assume every single person here has done. I've installed all the libraries that the course said to install, but the course never once explains how to open, modify, and execute this file. It looks like sys.path is calling the entire system path of my anaconda python environment executable and not the path of the python file being worked on. Why is this happening, and what is the fix?

Can someone who has actually figured this out please comment in plain text how to resolve this issue?

Edit: In lieu of an actual solution for what is causing the problem, I made a hard-coded workaround:

sys.path.insert(0, 'D:/Nano/ML/ud120-projects/tools')#sys.path.append("../tools/")Now I'm getting a whole new error message though...Traceback (most recent call last): File "", line 1, in File "D:/Nano/ML/ud120-projects/tools\email_preprocess.py", line 5, in import numpy File "C:\Users\Skyqu\Anaconda3\envs\py2\lib\site-packages\numpy_init_.py", line 142, in from . import core File "C:\Users\Skyqu\Anaconda3\envs\py2\lib\site-packages\numpy\core_init_.py", line 71, in raise ImportError(msg)ImportError:then a whole bunch of text about making sure Numpy is installed right and how to report the error to Numpy… then...
Original error was: DLL load failed: The specified module could not be found.

I verified that Numpy was installed on that environment.
So, what's the issue with Numpy, and how was sys.path.insert supposed to work if it's pulling the path from the python executable?

from ud120-projects.

abhiteshdas avatar abhiteshdas commented on August 16, 2024 1

Its solved now. I was using the Canopy editor, and it creates some sort of virtual environment I guess. When I installed the required packages on my local machine, it worked fine.

from ud120-projects.

raghunandepu avatar raghunandepu commented on August 16, 2024 1

I am also getting same error. Please advise. I am running the script under folder naïve_bayes only.

Error:

E:\UdMLearning\ud120-projects\naive_bayes>python nb_author_id.py
Traceback (most recent call last):
File "nb_author_id.py", line 16, in
from email_preprocess import preprocess
File "..\tools\email_preprocess.py", line 5, in
import numpy
ImportError: No module named numpy

E:\UdMLearning\ud120-projects\naive_bayes>where python
C:\Python27\python.exe
C:\Users\Raghu\Anaconda2\python.exe

I already have numpy installed as shown below.

E:\UdMLearning\ud120-projects\tools>conda install numpy
Fetching package metadata ...........
Solving package specifications: .

All requested packages already installed.
packages in environment at C:\Users\Raghu\Anaconda2:

numpy 1.13.1 py27_0

from ud120-projects.

BugByteBuster avatar BugByteBuster commented on August 16, 2024 1

hi all,
i am trying to run the nb_author_id file from naive_bayes folder but i am still getting the error as below, can anyone help me in sorting this issue

C:\Users\xxxxxxx\ud120-projects\naive_bayes>python nb_author_id.py
Traceback (most recent call last):
File "nb_author_id.py", line 14, in
from email_preprocess import preprocess
ImportError: No module named email_preprocess

from ud120-projects.

carlosughini avatar carlosughini commented on August 16, 2024 1

Hey guys, you just need to open the file email_preprocess.py inside the folder tools and change all references from cross_validation to model_selection.

from ud120-projects.

AM2037 avatar AM2037 commented on August 16, 2024 1

EDIT: RESOLVED !!! For anyone just joining this thread that is also struggling to get the import statements for your modules to work from the tools directory (or any directory) this is how I fixed it:
Put empty __init__.py files into the tools directories as well as any other directories you want to import the ones from tools into. I.e. naive_bayes for the nb_author_id.py file or in the svm folder to use the svm_author_id file. In the places I saw __init__ mentioned I wasn't clear on the fact that you needed more than one of these for it to work

Other things that help, plus some commands to run every single time you use anaconda:

  • When working in Git Bash using a conda environment, always run the command conda init bash first before doing anything else
  • If you haven't already created a 2nd python virtual environment do it with this command: conda create --name py2 python=2.7 since this project relies on that version of python. (you can set this to any name, not just py2)
  • Always activate the 2nd environment with the command source activate py2 and use conda deactivate py2 to deactivate when you are done, or simply close your terminal
  • OPTIONAL: Check which environment conda is currently running using the conda info command and then to be extra sure you're using the correct version of python run python -V or python --version

I hope this helps and you won't have to clean/uninstall/reinstall anaconda 3, the virtual env, and packages like I did. I literally have this entire process memorized at this point.

Original post: Has anyone figured this out? I've tried literally every solution on every forum, github page, etc. and still for the life of me cannot figure out how to stop getting the error "Unable to import email_preprocess" and "No module named email_preprocess"

I'm in the naive_bayes directory, I've set it to tools, I've created a 2nd python environment for python 2.7 and verified it's working, initiated git bash for conda, changed every cross_validation reference to model_selection, tried using double \ slashes instead of / for windows path, everything. It's still giving me an error. Please and thank you.

from ud120-projects.

mailaneel avatar mailaneel commented on August 16, 2024

thanks that worked.

from ud120-projects.

fernanhid avatar fernanhid commented on August 16, 2024

Hey Sheng,

I'm in the naive_bayes folder, but I don't quite understand how to run the script in git hub. I'm not too familiar with it, could you tell me what steps to take so that I can run the code?

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024

You should not be running the code in GitHub. The easiest thing is to download a copy of the repository so that you can work on it on your local computer. If you go to the home page of the repository, there'll be a button on the page that says "Download ZIP". Click on it, extract the archive to a folder, and you should be good to go for starting on the course materials.

from ud120-projects.

fernanhid avatar fernanhid commented on August 16, 2024

Thanks Sheng, it all works fine now :)

from ud120-projects.

ripuasu avatar ripuasu commented on August 16, 2024

rksingh-MAC:ud120-projects-master rksingh$ ./naive_bayes/nb_author_id.py
Traceback (most recent call last):
File "./naive_bayes/nb_author_id.py", line 16, in
from email_preprocess import preprocess
ImportError: No module named email_preprocess

still not sure how to run the code.
Appreciate any help

from ud120-projects.

ripuasu avatar ripuasu commented on August 16, 2024

thanks Sheng...
Appreciate your help..
But now i m getting this error:
rksingh-MAC:naive_bayes rksingh$ ./nb_author_id.py
Traceback (most recent call last):
File "./nb_author_id.py", line 16, in
from email_preprocess import preprocess
File "../tools/email_preprocess.py", line 5, in
import numpy
ImportError: No module named numpy
rksingh-MAC:naive_bayes rksingh$ pwd
/Users/rksingh/Desktop/DATA_ANALYTICS/ud120-projects-master/naive_bayes

Do u see any issue with the setup...

thanks,

from ud120-projects.

ripuasu avatar ripuasu commented on August 16, 2024

got it...problem fixed..thanks for help

from ud120-projects.

sandeshprabhu avatar sandeshprabhu commented on August 16, 2024

Hi ripuasu, Could you please help me understand how did you solve the above issue in detail? thanks a ton!

from ud120-projects.

abhiteshdas avatar abhiteshdas commented on August 16, 2024

Even I am facing the same issue, hence, created a new issue.
#50 - @sandeshprabhu pls subscribe there as the current issue is already closed and I don't expect anyone to look into a closed issue.

from ud120-projects.

JF-13 avatar JF-13 commented on August 16, 2024

Hey ShengKungYi,

im running from the folder I extracted from downloaded file using python gui and im getting this error...

moved the folder to c:\python27 and still have the same issue

I get error:
Traceback (most recent call last):
File "C:\Python27\ud120-projects-master\naive_bayes\nb_author_id.py", line 16, in
from email_preprocess import preprocess
ImportError: No module named email_preprocess

from ud120-projects.

JF-13 avatar JF-13 commented on August 16, 2024

That helped!! thank you!!
Its still not working but its because its "no module named scipy" I try installing it with "pip install scipy" but I get "error code 1". I looked it up and people say to update pip but I checked and I am running the latest version.
I couldn't find a thread talking about this..

IDK if its related but when I run the startup.py it stated that I shouldnt keep going without installing scipy and then when it unzips it never says completed and ive left it for a few hrs at a time

from ud120-projects.

codeloverguy avatar codeloverguy commented on August 16, 2024

Hi all,

below is the python code.I have been running it from the naive bayes folder but still getting error

import sys
from time import time
sys.path.append("C:\Python27\Tools\ud120-projects-master\ud120-projects-master")
from email_preprocess import preprocess

error I am getting:
ImportError: No module named email_preprocess

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024

It looks like your sys.path.append() expression isn't adding the correct folder to the path. As noted above, the email_preprocess.py script is in the tools folder; this folder should be indicated in the function argument instead. Could you try reverting the code to its original form and try again?

from ud120-projects.

codeloverguy avatar codeloverguy commented on August 16, 2024

Hi Sheng,
Thanks for taking out your time to reply.
I am a bit noob out here.I have just started python for the Udacity course.
What I am doing out here is that I am keeping all the required files (including email_preprocess.py) into the "naive _ayes" folder and running the code.
now I am using this as below
sys.path.append("C:\Python27\Tools\ud120-projects-master\ud120-projects-master\naive_bayes")
now its throwing me error that

IOError: [Errno 2] No such file or directory: '../tools/email_authors.pkl'

but I can see the file in the "naive_bayes" folder.
What wrong I am doing out here

from ud120-projects.

codeloverguy avatar codeloverguy commented on August 16, 2024

is it a possibility our code is not able to read the pkl file?

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024

If you're just getting started with Python, I would suggest taking some time to familiarize yourself with how to use it first before going through the Intro to Machine Learning course. The course will not teach you Python, as it expects some programming proficiency coming into the program.

To address your question, the email_preprocess.py script expects to be imported from a different folder so having a copy of it inside of the "naive_bayes" folder will break things. As before, I suggest keeping the project files in their original structure, and make sure that you are running the script directly from the "naive_bayes" folder.

from ud120-projects.

fernanhid avatar fernanhid commented on August 16, 2024

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024

I think you can unsubscribe from the issue by using the button on the right side of the page.

from ud120-projects.

huakaibubai1991 avatar huakaibubai1991 commented on August 16, 2024

hello,ShengKungYi,there are always the error,can you help me to solve it?
Traceback (most recent call last):

File "", line 1, in
runfile('C:/Users/lenovo/Desktop/ud120-projects-master/ud120-projects-master/naive_bayes/nb_author_id.py', wdir='C:/Users/lenovo/Desktop/ud120-projects-master/ud120-projects-master/naive_bayes')

File "C:\Users\lenovo\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

File "C:\Users\lenovo\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:/Users/lenovo/Desktop/ud120-projects-master/ud120-projects-master/naive_bayes/nb_author_id.py", line 32, in
clf.fit(features_train,labels_train)

File "C:\Users\lenovo\Anaconda2\lib\site-packages\sklearn\naive_bayes.py", line 184, in fit
sample_weight=sample_weight)

File "C:\Users\lenovo\Anaconda2\lib\site-packages\sklearn\naive_bayes.py", line 406, in _partial_fit
X_i, sw_i)

File "C:\Users\lenovo\Anaconda2\lib\site-packages\sklearn\naive_bayes.py", line 237, in _update_mean_variance
new_var = np.var(X, axis=0)

File "C:\Users\lenovo\Anaconda2\lib\site-packages\numpy\core\fromnumeric.py", line 3177, in var
**kwargs)

File "C:\Users\lenovo\Anaconda2\lib\site-packages\numpy\core_methods.py", line 101, in _var
x = asanyarray(arr - arrmean)

MemoryError

from ud120-projects.

jajsda avatar jajsda commented on August 16, 2024

(aind) C:\Users\Administrator>python C:\Users\Administrator\Desktop\AIND-Sudoku-master\solution_test.py
...

Ran 3 tests in 0.016s

OK

(aind) C:\Users\Administrator>udacity submit C:\Users\Administrator\Desktop\AIND-Sudoku-master
Traceback (most recent call last):
File "c:\users\administrator\anaconda3\envs\aind\lib\site-packages\udacity_pa\projectassistant.py", line 34, in
import projects
ModuleNotFoundError: No module named 'projects'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\administrator\anaconda3\envs\aind\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\users\administrator\anaconda3\envs\aind\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\Administrator\Anaconda3\envs\aind\Scripts\udacity.exe_main
.py", line 5, in
File "c:\users\administrator\anaconda3\envs\aind\lib\site-packages\udacity_pa\projectassistant.py", line 39, in
raise NotProjectAssistantError()
udacity_pa.projectassistant.NotProjectAssistantError

(aind) C:\Users\Administrator>

from ud120-projects.

Amit-Chouksey avatar Amit-Chouksey commented on August 16, 2024

I saved the email_preprocess file from github and its showing that the error is of invalid syntax.

File "F:/lucky/udacity github/dt_author_id.py", line 14, in
from email_preprocess import preprocess
File "F:\lucky\udacity github\email_preprocess.py", line 62
print "no. of Chris training emails:", sum(labels_train)
^
SyntaxError: invalid syntax

from ud120-projects.

ShengKungYi avatar ShengKungYi commented on August 16, 2024

@Amit-Chouksey It looks like you're running the code in Python 3, which has a different syntax for print statements. All of the course materials have been created with Python 2.7 in mind, so you'll need to either use Python 2 or make the appropriate adjustments to the code in order to get it to run under Python 3.

from ud120-projects.

SrGrace avatar SrGrace commented on August 16, 2024

$ git clone https://github.com/udacity/ud120-projects.git
Cloning into 'ud120-projects'...
fatal: unable to access 'https://github.com/udacity/ud120-projects.git/': Couldn't resolve host 'github.com'

from ud120-projects.

shs86420 avatar shs86420 commented on August 16, 2024

ImportError Traceback (most recent call last)
in ()
14 from time import time
15 sys.path.append("C:/Users/Sh/ud120-projects-master/tools/")
---> 16 from email_preprocess import preprocess
17
18

C:/Users/Shivani Singh/ud120-projects-master/tools/email_preprocess.py in ()
3 import pickle
4 import cPickle
----> 5 import numpy
6
7 from sklearn import cross_validation

ImportError: No module named numpy

#I had downloaded anaconda for python3 but to do this project ,opened it in python2
#What should I do?

from ud120-projects.

jose-raul-barreras avatar jose-raul-barreras commented on August 16, 2024

If your problem occurs in Windows, change / to \\ should be enough

import sys
from time import time
sys.path.append("..\\tools\\")
from email_preprocess import preprocess

from ud120-projects.

Shubhi-Jain98 avatar Shubhi-Jain98 commented on August 16, 2024

Hi all
I am getting an error as given below. Can someone please help me in solving this....

C:\Python27>nb_author_id.py
C:\Python27\lib\site-packages\sklearn\cross_validation.py:41: DeprecationWarning
: This module was deprecated in version 0.18 in favor of the model_selection mod
ule into which all the refactored classes and functions are moved. Also note tha
t the interface of the new CV iterators are different from that of this module.
This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Traceback (most recent call last):
File "C:\Users\lenovo\Desktop\github_ml\C_Users_lenovo_code\ud120-projects\2_n
aive_bayes\nb_author_id.py", line 52, in
features_train, features_test, labels_train, labels_test = preprocess()
File "C:\Users\lenovo\Desktop\github_ml\C_Users_lenovo_code\ud120-projects\2_n
aive_bayes\email_preprocess.py", line 32, in preprocess
authors_file_handler = open(authors_file, "r")
IOError: [Errno 2] No such file or directory: '../tools/email_authors.pkl'

from ud120-projects.

zhangsheng377 avatar zhangsheng377 commented on August 16, 2024

do you have the '../tools/email_authors.pkl' ?

from ud120-projects.

Shubhi-Jain98 avatar Shubhi-Jain98 commented on August 16, 2024

ya i have that....

from ud120-projects.

mbuguanewton avatar mbuguanewton commented on August 16, 2024

hello,
Am currently using python 3 and am getting this error: from email_preprocess import preprocess
ModuleNotFoundError: No module named 'email_preprocess'. Is it something to do with the python version? I have tried running it multiple times from the naive_bayes folder but I keep getting the error. Also, I have searched for the syntax that needs to be changed to python 3 version but the syntax is similar.
Please help!!

from ud120-projects.

Manukam avatar Manukam commented on August 16, 2024

Hi All,
If you have Python 3.x, uninstall and install python 2.7 or convert the files from python 3 to 2.

from ud120-projects.

infinity-ai avatar infinity-ai commented on August 16, 2024

to make the svm code run using email_preprocess.py use this line
from tools.email_preprocess import preprocess

#the email_preprocess.py script is in tools directory
#182

from ud120-projects.

maibkey avatar maibkey commented on August 16, 2024

python svm/svm_author_id.py
Traceback (most recent call last):
File "svm/svm_author_id.py", line 14, in
from email_preprocess import preprocess
ModuleNotFoundError: No module named 'email_preprocess'

can you tell me how to solve this problem,and I don't understand what do you mean above what you said

from ud120-projects.

Manukam avatar Manukam commented on August 16, 2024

Which version of python are you using ?

from ud120-projects.

maibkey avatar maibkey commented on August 16, 2024

from ud120-projects.

rajatyad avatar rajatyad commented on August 16, 2024

Getting this issue when I try to load the Naive bayes py file

Traceback (most recent call last):
File "C:\Users\Rajat Yadav\Documents\GitHub\ud120-projects\naive_bayes\nb_author_id.py", line 16, in
from email_preprocess import preprocess
File "../tools/email_preprocess.py", line 7, in
from sklearn import cross_validation
ImportError: cannot import name cross_validation

from ud120-projects.

Boosmith avatar Boosmith commented on August 16, 2024

@tzenga Thanks that fixed it for me. I'm going to create a PR for this, if I can....

from ud120-projects.

vinindersingh avatar vinindersingh commented on August 16, 2024

@ShengKungYi I am facing this issue.

import sys
from time import time
sys.path.append("/Users/vininderbaweja/Documents/ud120-projects-master/tools/email_preprocess.py")
from email_preprocess import preprocess


ImportError Traceback (most recent call last)
in ()
2 from time import time
3 sys.path.append("/Users/vininderbaweja/Documents/ud120-projects-master/tools/")
----> 4 from email_preprocess import preprocess
5

/Users/vininderbaweja/Documents/ud120-projects-master/tools/email_preprocess.py in ()
5 import numpy
6
----> 7 from sklearn import cross_validation
8 from sklearn.feature_extraction.text import TfidfVectorizer
9 from sklearn.feature_selection import SelectPercentile, f_classif

ImportError: cannot import name cross_validation

from ud120-projects.

whrocha avatar whrocha commented on August 16, 2024

I can't run the code in Visual Code.
I still having the problem

Unable to import 'email_preprocess'

from ud120-projects.

whrocha avatar whrocha commented on August 16, 2024

You should be running the script directly from the naive_bayes folder. This is because email_preprocess.py is found in the tools folder, thus the need for the statement made on the immediately preceding line (16).

But i'm running inside VS Code and I still having problems

from ud120-projects.

szelesaron avatar szelesaron commented on August 16, 2024

I tried everything, but it's just giving me the No module named 'email_preprocess' error. And yes I am running it from the correct folder. I am using spyder.

from ud120-projects.

Nivitus avatar Nivitus commented on August 16, 2024

thanks that worked.

can you please explain that for me

from ud120-projects.

freecoders13 avatar freecoders13 commented on August 16, 2024

Traceback (most recent call last):
File "D:/ud120-projects-master/naive_bayes/nb_author_id.py", line 16, in
from email_preprocess import preprocess
ImportError: No module named email_preprocess

And yes, I'm running it directly from the naive_bayes folder. guys I'm fed up now.I was glad learning but it seems useless to me now. :(

from ud120-projects.

Isaac1m avatar Isaac1m commented on August 16, 2024

If you're using Windows, change sys.path.append(../tools/) to sys.path.append("..\\tools\\")

from ud120-projects.

jcrantek avatar jcrantek commented on August 16, 2024

EDIT: RESOLVED !!! For anyone just joining this thread that is also struggling to get the import statements for your modules to work from the tools directory (or any directory) this is how I fixed it:
Put empty __init__.py files into the tools directories as well as any other directories you want to import the ones from tools into. I.e. naive_bayes for the nb_author_id.py file or in the svm folder to use the svm_author_id file. In the places I saw __init__ mentioned I wasn't clear on the fact that you needed more than one of these for it to work

Other things that help, plus some commands to run every single time you use anaconda:

  • When working in Git Bash using a conda environment, always run the command conda init bash first before doing anything else
  • If you haven't already created a 2nd python virtual environment do it with this command: conda create --name py2 python=2.7 since this project relies on that version of python. (you can set this to any name, not just py2)
  • Always activate the 2nd environment with the command source activate py2 and use conda deactivate py2 to deactivate when you are done, or simply close your terminal
  • OPTIONAL: Check which environment conda is currently running using the conda info command and then to be extra sure you're using the correct version of python run python -V or python --version

I hope this helps and you won't have to clean/uninstall/reinstall anaconda 3, the virtual env, and packages like I did. I literally have this entire process memorized at this point.

Original post: Has anyone figured this out? I've tried literally every solution on every forum, github page, etc. and still for the life of me cannot figure out how to stop getting the error "Unable to import email_preprocess" and "No module named email_preprocess"

I'm in the naive_bayes directory, I've set it to tools, I've created a 2nd python environment for python 2.7 and verified it's working, initiated git bash for conda, changed every cross_validation reference to model_selection, tried using double \ slashes instead of / for windows path, everything. It's still giving me an error. Please and thank you.

I too am stuck here. I've tried everything mentioned and really this should be a simple fix. We are just attempting to reference another python file in another folder. My next step is just to dump everything in the same naive_bayes folder. Let's see if that helps.

**Edit - Copying everything from the tools folder into the naive_bayes folder removed the error. Now I'll see if I can remedy the original issue.

**Edit2 - Alright this is interesting. I copied everything inside of the tools folder into the naive_bayes folder. Didn't change the import statement at all from what was originally given to us. The import error went away. Now I moved all of the files back to the tools directory leaving only nb_author_id.py in the naive_bayes folder. I changed the import statement to 'from tools.email_preprocess import preprocess' and the error is gone. It's almost as it needed to see the file in the same directory and then it could find it in another directory as long as it was referenced correctly. Hope this helps.

from ud120-projects.

AM2037 avatar AM2037 commented on August 16, 2024

@Deucer I've already solved this issue -- did you try using empty init.py files in each of the folders you are trying to import from and into?

from ud120-projects.

jcrantek avatar jcrantek commented on August 16, 2024

@Deucer I've already solved this issue -- did you try using empty init.py files in each of the folders you are trying to import from and into?

I did place empty init.py files in the working directories and still received the import error.

from ud120-projects.

AM2037 avatar AM2037 commented on August 16, 2024

@Deucer interesting, the init files alone worked for me and I didn't have to change the import line - what I did do however was make the tools directory a source in my pycharm editor

from ud120-projects.

melatronics avatar melatronics commented on August 16, 2024

Couldn't get any of these solutions to work for me. The fix for me was to remove the "-" in the file path to where the project was stored.

For example, the original directory I unzipped the files into was:
C:\Users\myusername\Documents\school\ud120-projects

I renamed it to be:
C:\Users\myusername\Documents\school\ud120projects
The errors are gone after this.

from ud120-projects.

AM2037 avatar AM2037 commented on August 16, 2024

@melatronics I was able to save it with the dash in the name

from ud120-projects.

issa24 avatar issa24 commented on August 16, 2024

The easiest way to solve this issue, for once and all, is to follow the steps below:

  1. First install Python version 2.7 64-bit (to avoid memory errors at execution stages)
  2. Open your Udacity project file in CMD or PowerShell, e.g., 'C:\Users\ab\Downloads\ud120-projects-master.'
  3. Enter "pipenv --two" to create virtual environment in a project file -- like this 'C:\Users\ab\Downloads\ud120-projects-master> pipenv --two'
  4. Enter "pipenv shell" to launch the virtual environment
  5. Now try to install all the packages for the project, e.g., "pip install numpy, scikit-learn, nltk==3.4.5."
  6. Finally, make sure you update sklearn in your email_preprocess.py file to "from sklearn.model_selection import train_test_split" and also, your file path should look like this sys.path.append("tools") in your naives_bayes folder- nb_author_id.py (At least, in my case!)
  7. Hopefully, you encounter no problems after following the above steps!

from ud120-projects.

vincentarck avatar vincentarck commented on August 16, 2024

You should be running the script directly from the naive_bayes folder. This is because email_preprocess.py is found in the tools folder, thus the need for the statement made on the immediately preceding line (16).

hello sir, why when i se to open directly nb_author_id in naive_bayes folder the command prompt got force close

from ud120-projects.

MaadMat avatar MaadMat commented on August 16, 2024

I ran into this

Traceback (most recent call last):
File "nb_author_id.py", line 26, in
features_train, features_test, labels_train, labels_test = preprocess()
File "../tools\email_preprocess.py", line 35, in preprocess
word_data = joblib.load(words_file_handler)
File "C:\Users\madmat\AppData\Local\Programs\Python\Python38\lib\site-packages\joblib\numpy_pickle.py", line 577, in load
obj = _unpickle(fobj)
File "C:\Users\madmat\AppData\Local\Programs\Python\Python38\lib\site-packages\joblib\numpy_pickle.py", line 506, in _unpickle
obj = unpickler.load()
File "C:\Users\madmat\AppData\Local\Programs\Python\Python38\lib\pickle.py", line 1210, in load
dispatchkey[0]
File "C:\Users\madmat\AppData\Local\Programs\Python\Python38\lib\pickle.py", line 1334, in load_string
raise UnpicklingError("the STRING opcode argument must be quoted")
_pickle.UnpicklingError: the STRING opcode argument must be quoted
PS C:\Users\madmat\mooc\ml\naive_bayes>

from ud120-projects.

bryanekong avatar bryanekong commented on August 16, 2024

You should be running the script directly from the naive_bayes folder. This is because email_preprocess.py is found in the tools folder, thus the need for the statement made on the immediately preceding line (16).

Hello I ran it from the naive_baiyes folder and I still had that error, what do I do?

from ud120-projects.

MaadMat avatar MaadMat commented on August 16, 2024

I'm in your position

from ud120-projects.

Badrgamalahmed avatar Badrgamalahmed commented on August 16, 2024

from ud120-projects.

Badrgamalahmed avatar Badrgamalahmed commented on August 16, 2024

from ud120-projects.

SabalNiroula avatar SabalNiroula commented on August 16, 2024

I have successfully solved this error by doing this :

1. copy all the files of tools into naive_bayes and still you would be seeing error like this:

Traceback (most recent call last):
File "e:\Download\ud120-projects-master\naive_bayes\nb_author_id.py", line 22, in
features_train, features_test, labels_train, labels_test = preprocess()
File "e:\Download\ud120-projects-master\naive_bayes\email_preprocess.py", line 30, in preprocess
authors_file_handler = open(authors_file, "rb")

2. In naive bayes folder there is email_preprocess file, you can see words_file = "../tools/word_data.pkl" . Now change words file = "naive_bayes/word_data.pkl" . Similarly change the author file location to mentioned above and all the errors will be gone.

from ud120-projects.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.