Python Forum
FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles
#1
I make directory and sub directory in the same project to train and fit my model still get an error
FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles.csv'
Quote:

X = pd.read_csv("model/doc2vec.model/Articles.csv", index_col='id')
X.head()
Quote:Overall errors

Error:
D:\Python3.8.0\Python\python.exe D:/Clustering/text-cluster-master/similarity.py Traceback (most recent call last): File "D:/Clustering/text-cluster-master/similarity.py", line 58, in <module> X = pd.read_csv("model/doc2vec.model/Articles.csv", index_col='id') File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 605, in read_csv return _read(filepath_or_buffer, kwds) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 457, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 814, in __init__ self._engine = self._make_engine(self.engine) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 1045, in _make_engine return mapping[engine](self.f, **self.options) # type: ignore[call-arg] File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 1862, in __init__ self._open_handles(src, kwds) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 1357, in _open_handles self.handles = get_handle( File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\common.py", line 639, in get_handle handle = open( FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles.csv'
Reply
#2
With a relative path, Python looks for the file relatively to the current working directory of the current process. Is it the same as the directory containing the 'model' directory ?
Reply
#3
On Windows as you use most give absolute path.
Example if Articles.csv is in that folder on D:\ drive.
X = pd.read_csv("D:/model/doc2vec.model/Articles.csv", index_col='id') 
The other option is to have Articles.csv in same folder as similarity.py then you give no path.
X = pd.read_csv("Articles.csv", index_col='id')
Reply
#4
You can also give more complex paths relative to the python file's directory
from pathlib import Path
thisdir = Path(__file__).parent
csv = thisdir/'..'/'..'/'spam'/'Articles.csv'
Anldra12 likes this post
Reply
#5
@Gribouillis yeah thanks but complex path is not seen good
Reply
#6
(Jun-11-2021, 02:24 PM)snippsat Wrote: On Windows as you use most give absolute path.
Example if Articles.csv is in that folder on D:\ drive.
X = pd.read_csv("D:/model/doc2vec.model/Articles.csv", index_col='id') 
The other option is to have Articles.csv in same folder as similarity.py then you give no path.
X = pd.read_csv("Articles.csv", index_col='id')

@snippsat thanks yeah i check where the exact problem
Reply
#7
@Gribouillis yeah thanks but complex path is not seen good
Reply
#8
after apply the abs path it return another error

X = pd.read_csv("D:\Clustering\text-cluster-master\text-cluster-master", index_col='id')
X.head()
Error:
D:\Python3.8.0\Python\python.exe D:/Clustering/text-cluster-master/similarity.py Traceback (most recent call last): File "D:/Clustering/text-cluster-master/similarity.py", line 58, in <module> X = pd.read_csv('Articles.csv', index_col='id') File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 605, in read_csv return _read(filepath_or_buffer, kwds) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 463, in _read return parser.read(nrows) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 1052, in read index, columns, col_dict = self._engine.read(nrows) File "D:\Python3.8.0\Python\lib\site-packages\pandas\io\parsers.py", line 2056, in read data = self._reader.read(nrows) File "pandas\_libs\parsers.pyx", line 756, in pandas._libs.parsers.TextReader.read File "pandas\_libs\parsers.pyx", line 771, in pandas._libs.parsers.TextReader._read_low_memory File "pandas\_libs\parsers.pyx", line 827, in pandas._libs.parsers.TextReader._read_rows File "pandas\_libs\parsers.pyx", line 814, in pandas._libs.parsers.TextReader._tokenize_rows File "pandas\_libs\parsers.pyx", line 1951, in pandas._libs.parsers.raise_parser_error pandas.errors.ParserError: Error tokenizing data. C error: Expected 9 fields in line 4, saw 10
Reply
#9
You can not do it like this and singel \ will mess up path because of escape character.
# \t is Tab,see the space so path will never work like this
>>> s = 'D:\text-cluster-master'
>>> print(s)
D:	ext-cluster-master
You most also point to the exacts placement of the file and the folder.
# Turn backslash this
X = pd.read_csv("D:/Clustering/text-cluster-master/text-cluster-master/Articles.csv", index_col='id')

# Or use raw string
X = pd.read_csv(r"D:\Clustering\text-cluster-master\text-cluster-master\Articles.csv", index_col='id')
Reply
#10
@snippsat yeah you are right still i have same error
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 263 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  model.fit and model.predict errors hatflyer 6 1,319 Nov-10-2023, 01:39 AM
Last Post: hatflyer
  Modify an Energy Model to account for year dependent interest rate rather than only t giovanniandrean 0 426 Oct-10-2023, 07:00 AM
Last Post: giovanniandrean
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,572 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,344 Jun-27-2023, 01:17 PM
Last Post: diver999
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 998 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,124 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,547 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 1,029 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Failed to execute child process (No such file or directory) uriel 1 1,655 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