Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49544 > unrolled thread
| Started by | prerit86@gmail.com |
|---|---|
| First post | 2013-07-01 03:47 -0700 |
| Last post | 2013-07-01 05:17 -0700 |
| Articles | 9 — 4 participants |
Back to article view | Back to comp.lang.python
File exists but Python says 'not found'. prerit86@gmail.com - 2013-07-01 03:47 -0700
Re: File exists but Python says 'not found'. Robert Kern <robert.kern@gmail.com> - 2013-07-01 11:56 +0100
Re: File exists but Python says 'not found'. prerit86@gmail.com - 2013-07-01 03:57 -0700
Re: File exists but Python says 'not found'. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-07-01 13:15 +0200
Re: File exists but Python says 'not found'. prerit86@gmail.com - 2013-07-01 04:32 -0700
Re: File exists but Python says 'not found'. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-07-01 12:59 +0200
Re: File exists but Python says 'not found'. prerit86@gmail.com - 2013-07-01 04:00 -0700
Re: File exists but Python says 'not found'. Dave Angel <davea@davea.name> - 2013-07-01 07:38 -0400
Re: File exists but Python says 'not found'. prerit86@gmail.com - 2013-07-01 05:17 -0700
| From | prerit86@gmail.com |
|---|---|
| Date | 2013-07-01 03:47 -0700 |
| Subject | File exists but Python says 'not found'. |
| Message-ID | <5c1d1e47-b67e-4bce-8601-b14c0215f450@googlegroups.com> |
I'm running this code that reads 2 csv files (one of them is train.csv). The code gives an error saying 'file not does not exist'. However, the file does exists in the same location as the .py file. Can someone please help me on this. Thanks!
Code Output-->
Reading dataset...
Traceback (most recent call last):
File "c:\Project_1\regression_2.py", line 163, in <module>
main(**args)
File "c:\Project_1\regression_2.py", line 80, in main
train_data = pd.read_csv(train)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 401, in parser
_f
return _read(filepath_or_buffer, kwds)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 209, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 509, in __init
__
self._make_engine(self.engine)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 611, in _make_
engine
self._engine = CParserWrapper(self.f, **self.options)
File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 893, in __init
__
self._reader = _parser.TextReader(src, **kwds)
File "parser.pyx", line 312, in pandas._parser.TextReader.__cinit__ (pandas\sr
c\parser.c:2846)
File "parser.pyx", line 512, in pandas._parser.TextReader._setup_parser_source
(pandas\src\parser.c:4893)
IOError: File train.csv does not exist
[toc] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2013-07-01 11:56 +0100 |
| Message-ID | <mailman.4062.1372676220.3114.python-list@python.org> |
| In reply to | #49544 |
On 2013-07-01 11:47, prerit86@gmail.com wrote:
> I'm running this code that reads 2 csv files (one of them is train.csv). The code gives an error saying 'file not does not exist'. However, the file does exists in the same location as the .py file. Can someone please help me on this. Thanks!
How are you running the code? If you are doing pandas.read_csv('train.csv'), the
file must be in the current working directory of the running process. The
location of the .py file contain the code is not relevant. For example, if you
are using an IDE to run the script, you may need to configure how it runs the
script to pick a particular directory for it to run in.
> Code Output-->
>
> Reading dataset...
> Traceback (most recent call last):
> File "c:\Project_1\regression_2.py", line 163, in <module>
> main(**args)
> File "c:\Project_1\regression_2.py", line 80, in main
> train_data = pd.read_csv(train)
Since the filename of regression_2.py in the traceback is fully-qualified, I
expect that you are running the program from something other than the
c:\Project_1\ directory.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
[toc] | [prev] | [next] | [standalone]
| From | prerit86@gmail.com |
|---|---|
| Date | 2013-07-01 03:57 -0700 |
| Message-ID | <e43b906e-a587-4711-8f60-a5e25d4f00c7@googlegroups.com> |
| In reply to | #49544 |
The variable 'train' is being called like this ->
def main(train='train.csv', test='test.csv', submit='logistic_pred.csv'):
print "Reading dataset..."
train_data = pd.read_csv(train)
test_data = pd.read_csv(test)
Let me know if I need to post the full code.
[toc] | [prev] | [next] | [standalone]
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2013-07-01 13:15 +0200 |
| Message-ID | <mailman.4064.1372677314.3114.python-list@python.org> |
| In reply to | #49546 |
Op 01-07-13 12:57, prerit86@gmail.com schreef: > The variable 'train' is being called like this -> > > def main(train='train.csv', test='test.csv', submit='logistic_pred.csv'): > print "Reading dataset..." > train_data = pd.read_csv(train) > test_data = pd.read_csv(test) > > Let me know if I need to post the full code. I think Robert wanted to know how you started the program. What instruction do you use to launch? In what directory are you launching your program? Is that the same directory where train.csv is present?
[toc] | [prev] | [next] | [standalone]
| From | prerit86@gmail.com |
|---|---|
| Date | 2013-07-01 04:32 -0700 |
| Message-ID | <95b8480f-5011-498e-bf36-278b89dced3a@googlegroups.com> |
| In reply to | #49549 |
My answers I think Robert wanted to know how you started the program. What instruction do you use to launch? - used command c:\python27\python.exe c:\project_1\code.py In what directory are you launching your program? - working directory was c: - python is in c:\python27 - code was in c:\project_1 - changed the working directory to c:\project_1 now and it worked Is that the same directory where train.csv is present? - train.csv is present in c:\project_1
[toc] | [prev] | [next] | [standalone]
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2013-07-01 12:59 +0200 |
| Message-ID | <mailman.4063.1372676395.3114.python-list@python.org> |
| In reply to | #49544 |
Op 01-07-13 12:47, prerit86@gmail.com schreef: > I'm running this code that reads 2 csv files (one of them is train.csv). The code gives an error saying 'file not does not exist'. However, the file does exists in the same location as the .py file. Can someone please help me on this. Thanks! > > Code Output--> > > Reading dataset... > Traceback (most recent call last): > File "c:\Project_1\regression_2.py", line 163, in <module> > main(**args) > File "c:\Project_1\regression_2.py", line 80, in main > train_data = pd.read_csv(train) > File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 401, in parser > _f > return _read(filepath_or_buffer, kwds) > File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 209, in _read > parser = TextFileReader(filepath_or_buffer, **kwds) > File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 509, in __init > __ > self._make_engine(self.engine) > File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 611, in _make_ > engine > self._engine = CParserWrapper(self.f, **self.options) > File "c:\Python27\lib\site-packages\pandas\io\parsers.py", line 893, in __init > __ > self._reader = _parser.TextReader(src, **kwds) > File "parser.pyx", line 312, in pandas._parser.TextReader.__cinit__ (pandas\sr > c\parser.c:2846) > File "parser.pyx", line 512, in pandas._parser.TextReader._setup_parser_source > (pandas\src\parser.c:4893) > IOError: File train.csv does not exist My guess is that train.csv is a symbolic link that points to a file that doesn't exist. So looking at your directory you can see an entry but actualy trying to open it will fail. -- Antoon Pardon
[toc] | [prev] | [next] | [standalone]
| From | prerit86@gmail.com |
|---|---|
| Date | 2013-07-01 04:00 -0700 |
| Message-ID | <fc85cde6-7308-4858-8f89-c218a980e427@googlegroups.com> |
| In reply to | #49547 |
I got it. The working directory was different. Sorry, I'm new and didn't the working directory has to be the location of the data. I thought the location of .py file and data file should be same. Thanks! Es. Robert Kern.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-07-01 07:38 -0400 |
| Message-ID | <mailman.4065.1372678710.3114.python-list@python.org> |
| In reply to | #49548 |
On 07/01/2013 07:00 AM, prerit86@gmail.com wrote: > I got it. The working directory was different. Sorry, I'm new and didn't the working directory has to be the location of the data. I thought the location of .py file and data file should be same. Thanks! Es. Robert Kern. > Python didn't make that assumption, the author of the script did. By using a relative name like train.csv, he is implicitly forcing Python to use the current working directory. If he had wanted the file to be found in the same directory as one of the source files, he could have built an absolute path by using the __file__ attribute of the module. However, for non-const files, the source directory is generally a bad place to put them. Confounding things is the strange habit that Windows has of deciding that the script location *should* be your current directory. I believe Explorer does that if you right-click select a script. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | prerit86@gmail.com |
|---|---|
| Date | 2013-07-01 05:17 -0700 |
| Message-ID | <7fbe3171-417f-494e-a8b9-c02ffe2d5e14@googlegroups.com> |
| In reply to | #49551 |
I know. Had I written the code, I would have not done this. I just wanted to get some initial results by leveraging this code. I would now build on this to improve my work's accuracy. Thanks for the inputs!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web