Python Forum
FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles (/thread-33934.html)

Pages: 1 2


FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Anldra12 - Jun-11-2021

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'



RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Gribouillis - Jun-11-2021

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 ?


RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - snippsat - Jun-11-2021

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')



RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Gribouillis - Jun-11-2021

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'



RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Anldra12 - Jun-11-2021

@Gribouillis yeah thanks but complex path is not seen good


RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Anldra12 - Jun-11-2021

(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


RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Anldra12 - Jun-11-2021

@Gribouillis yeah thanks but complex path is not seen good


RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Anldra12 - Jun-11-2021

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



RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - snippsat - Jun-11-2021

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')



RE: FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles - Anldra12 - Jun-11-2021

@snippsat yeah you are right still i have same error