Python Forum
FileNotFoundError: [Errno 2] No such file or directory: 'word2vec.model'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileNotFoundError: [Errno 2] No such file or directory: 'word2vec.model'
#1
I am trying to implement word2vec model using genism while make the model Dir word2vec.model under main models
Dir Path
path = "models/word2vec.model"
Main codes lines where error
def loadModel(self):
        self.path = "word2vec.model"  # Word2Vec model path
        self.model = word2vec.Word2Vec.load(self.path)
        print("model loading completed")
        model.save("word2vec.model")
        return self.model

if __name__ == '__main__':
    tr.loadModel()
After check and loading model it return me this error

Error:
Traceback (most recent call last): File "D:/Clustering/text-cluster-master/text-cluster-master/Word2Vector.py", line 108, in <module> tr.loadModel() File "D:/Clustering/text-cluster-master/text-cluster-master/Word2Vector.py", line 29, in loadModel self.model = word2vec.Word2Vec.load(self.path) File "D:\Python3.8.0\Python\lib\site-packages\gensim\models\word2vec.py", line 1141, in load model = super(Word2Vec, cls).load(*args, **kwargs) File "D:\Python3.8.0\Python\lib\site-packages\gensim\models\base_any2vec.py", line 1230, in load model = super(BaseWordEmbeddingsModel, cls).load(*args, **kwargs) File "D:\Python3.8.0\Python\lib\site-packages\gensim\models\base_any2vec.py", line 602, in load return super(BaseAny2VecModel, cls).load(fname_or_handle, **kwargs) File "D:\Python3.8.0\Python\lib\site-packages\gensim\utils.py", line 435, in load obj = unpickle(fname) File "D:\Python3.8.0\Python\lib\site-packages\gensim\utils.py", line 1395, in unpickle with open(fname, 'rb') as f: File "D:\Python3.8.0\Python\lib\site-packages\smart_open\smart_open_lib.py", line 174, in open fobj = _shortcut_open( File "D:\Python3.8.0\Python\lib\site-packages\smart_open\smart_open_lib.py", line 346, in _shortcut_open return _builtin_open(local_path, mode, buffering=buffering, **open_kwargs) FileNotFoundError: [Errno 2] No such file or directory: 'word2vec.model'
Reply
#2
Hi,
You tell us the file with the models is "models/word2vec.model". But then in the code you assign something different:
        self.path = "word2vec.model"  # Word2Vec model path
        self.model = word2vec.Word2Vec.load(self.path)
And the error message is:
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'word2vec.model'
Most obvious is "word2vec.model" must not be quoted.
        self.path = word2vec.model  # Word2Vec model path
Anldra12 likes this post
Reply
#3
@ibreeden If remove quoted from " word2vect.model " this error
Error:
Traceback (most recent call last): File "D:/Clustering/text-cluster-master/text-cluster-master/Word2Vector.py", line 108, in <module> tr.loadModel() File "D:/Clustering/text-cluster-master/text-cluster-master/Word2Vector.py", line 28, in loadModel self.path = word2vec.model # Word2Vec model path AttributeError: module 'gensim.models' has no attribute 'model'
Reply
#4
I have to apologise, I did not read your code well enough. The truth is I am not sure what the solution is. You say the file with the models is:
path = "models/word2vec.model"
You do not say where in the program you have put this line. But perhaps line 2 of method loadModel() should be:
self.path = "models/word2vec.model"  # Word2Vec model path
( now with quotes again.)

But beware: "models/word2vec.model" is a relative path. Perhaps the program executes a chdir() to the right directory (the directory that contains the models subdirectory) but it may also be dependent of your current directory when you start the program. If you get "FileNotFoundError" then try to fill in the absolute path.
Reply
#5
@ibreeden the abs path for the this models in "D:\" the word2vec.model located at models
Abs path D:\Clustering\text-cluster-master\text-cluster-master\models\word2vec.model
while try with abs path it return me permission denied apply \ to double \\
"D:\\Clustering\\text-cluster-master\\text-cluster-master\\models\\word2vec.model"
Error:
File "D:\Python3.8.0\Python\lib\site-packages\smart_open\smart_open_lib.py", line 346, in _shortcut_open return _builtin_open(local_path, mode, buffering=buffering, **open_kwargs) PermissionError: [Errno 13] Permission denied: 'D:\\Clustering\\text-cluster-master\\text-cluster-master\\models\\word2vec.model'
Reply
#6
(Jul-04-2021, 10:48 PM)Anldra12 Wrote:
Error:
PermissionError: [Errno 13] Permission denied: 'D:\\Clustering\\text-cluster-master\\text-cluster-master\\models\\word2vec.model'
Well done. Now you are making progress. You only have to ask the owner of the file to give you permission to read the file.
Reply
#7
@ibreeden thanks for your precious time and assistance
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 815 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 452 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  model.fit and model.predict errors hatflyer 6 1,757 Nov-10-2023, 01:39 AM
Last Post: hatflyer
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,806 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 4,003 Jun-27-2023, 01:17 PM
Last Post: diver999
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 1,215 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,273 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,759 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 1,142 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Failed to execute child process (No such file or directory) uriel 1 1,758 Sep-15-2022, 03:48 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020