./source/vstoxx_data_31032014.h5`` does not exist - python

I am using ipython to compile my code, but I am faced with an error.
My code is the following:
import pandas as pd
h5=pd.HDFStore('./source/vstoxx_data_31032014.h5','r')
futures_data=h5['futures_data']
options_data=h5['options_data']
h5.close()
And the OS error is:
OS error ./source/vstoxx_data_31032014.h5`` does not exist
How do I overcome this problem?

You can check present directory using:
%pwd
If the output of the above is any different from where you have save the downloaded file, then you can copy the downloaded file to this location. That way, the command will start reading the file.
Alternatively if copy paste of the desired file is not feasible, then directory can also be changed using the following function:
os.chdir(path)

Related

Python/Jupyter getting a FileNotFoundError when attempting to read an excel file however said file is in the correct directory

data = pd.read_excel("ETH-USD")
I continually receive an error message informing me that the file cannot be found
this is despite the fact that
1: my directory has been changed within to Python to the same address as the folder where the excel file is stored
2: the file name is input exactly as displayed
Any ideas on why it is unable to find my file?
Is it possible that the excel file has an extension of .xlsx, but your file explorer is set to "hide file extensions"? Try:
data = pd.read_excel("ETH-USD.xlsx")
Or, see what's in the current directory by running:
import os
print(os.listdir())
A tip from the comments:
Windows tip too: hold Shift, right click the excel file and copy as path, then you can see its path (if you don't enable viewing file extensions in the file browser). –
creanion
Often when running python scripts from compilers the "working directory", or where you are running the script from doesn't match the location of your script, hence why I find it much more reliable to use this instead:
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
data = pd.read_excel(os.path.join(BASE_DIR,"ETH-USD")
To add, while I do not use Jupyter, in VSCode which I use, the working directory (which is where python looks for if you put a path in read_excel() but its not a full path) is often the current directory opened in there, so I expect a similar issue to be the reason for your issue.

running python from the terminal windows

I am testing to run a python file from the command prompt. Running a simple code like print('Hello world') is working. But if I run below code I get an error.
code:
import pandas as pd
df = pd.read_excel('Test.xlsx')
df.to_csv('_TEST.csv', ';')
Error:
FileNotFoundError: [Errno 2] No such file or directory: 'Test.xlsx'
The file is in the right directory. Because the code works on the IDE, Visual studio code.
I hope someone knows it
There are two case that Python does not recognize your files:
Let's say your scripts named hello.py
Case 1: you're running python hello.py and the files is somewhere else, say at another_folder/Test.xlsx then:
import pandas as pd
df = pd.read_excel('another_folder/Test.xlsx')
df.to_csv('_TEST.csv', ';')
Case 2: you're running python another_folder/hello.py and the files is also at the same folder, say another_folder/Test.xlsx then it is also:
import pandas as pd
df = pd.read_excel('another_folder/Test.xlsx')
df.to_csv('_TEST.csv', ';')
The reason is that you have to write the path of your files relative to of current working directory, not relative to the python file.
Hint: run pwd in command line to see what directory you're at.
If the file is in the right directory, it may be a problem with the directory in which you are executing the script. Change your directory in the command prompt to the same directory shown in the terminal in Visual Studio Code.

Jupyter gives IOError for .text file

I am using Jupyter notebook to import some data from a text file.
The folder from which I have imported the notebook has another file, data.txt but when I try to use the loadtxt() module, the following error appears:
IOError Traceback (most recent call last)
<ipython-input-4-a129a96139d0> in <module>()
----> 1 our_data = loadtxt("data.txt")
IOError: data.txt not found.
I looked for a solution and the manual in the notebook stated that the file may not be in the same directory or folder as your notebook.
I checked twice and found that the folder on my computer contains both the notebook and the data.txt file in the same location.
What is the issue?
The file is simply not in the folder of the output of this code
import os
print(os.getcwd())
You need to either put the data.txt file in this folder or load the file with a path the points to the file.
As far as I know, loadtxt() method is from numpy, so you should addimport numpy as np and use it as np.loadtxt().
Hope this helps!
Can you try using a full path instead of just data.txt?
Maybe the current directory for jupyter is not where the notebook is.
Or you could try printing the current directory, or current directory contents like this to be sure:
import os;print(os.listdir("."))

TensorFlow - object detection module, error appear when trying to use protoc

having problems with protoc, the line doesn't work in windows.
I get this errors:
using this line
protoc --proto_path=./object_detection/protos --python_out=c:\testmomo ./object_detection/protos/anchor_generator.proto
I get this error
object_detection/protos/grid_anchor_generator.proto: File not found.
object_detection/protos/ssd_anchor_generator.proto: File not found.
anchor_generator.proto: Import "object_detection/protos/grid_anchor_generator.proto" was not found or had errors.
anchor_generator.proto: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
anchor_generator.proto:12:5: "GridAnchorGenerator" is not defined.
anchor_generator.proto:13:5: "SsdAnchorGenerator" is not defined.
what is the problem??
I was trying different things, and figured out where was the problem.
Make sure you're doing it this way:
# From models/
protoc object_detection/protos/*.proto --python_out=.
whereas I was trying to do it like:
# from object_detection/
protoc protos/*.proto --python_out=.
that gives me errors as yours.
Check if you're in the right place (directory).
First make note protoc buffer is quite dumb and does not catches all the files properly, you have two options to manually compile all the 29 files or follow below steps.
Copy the protoc exe file to folder where all the proto files are ie
"models-master\models-master\research\object_detection\protos"
Next open all the files in folder "models-master\research\object_detection\protos" using notepad++.
Press ctrl+f and remove "object_detection/protos/" in all the files
( if you are doing manually also remember the protoc starts in alphabetic order so start from file "anchor_generator.proto").
For example replace:-
import "object_detection/protos/grid_anchor_generator.proto";
import "object_detection/protos/ssd_anchor_generator.proto";
import "object_detection/protos/multiscale_anchor_generator.proto";
with this:-
import "grid_anchor_generator.proto";
import "ssd_anchor_generator.proto";
import "multiscale_anchor_generator.proto";
4.Now open Cmd in the same directory ie
"\models master\research\object_detection\protos"
type:-
protoc *.proto --python_out=.
notice you will get new .py file in the folder and no errors on execution of above file.
5.output:-
Note:- make sure you open all files and try using the output of step 4 to locate the missing files.
seems like there is no file: object_detection/protos/grid_anchor_generator.proto and ssd_ancho_generator.proto
did you just clone the models repostitory or have modified something?
In object_detection protos folder the import line is given
import "object_detection/protos/grid_anchor_generator.proto";
Change that to
import "research/object_detection/protos/grid_anchor_generator.proto";
Simply, run protocbuf for each one of them.
protoc object_detection/protos/grid_anchor_generator.proto
--python_out=.

Why do I get a "no such file or directory" error when the file is known to exist?

I have uploaded a package to pypi and github. I have then installed the package and tried to use it. It contains a python script which need to read from a file. I have placed both in the same directory.
pip install pycricket
from pycricket import cricket
c = cricket.Cricket()
c.query()
Query() function involves reading from a file. When I see the 'pycricket' package in library, both script as well as file are in same folder.
query():
with open('matches.csv', 'r') as f:
#code
I don't know why I get the error.
You can inspect the current working directory with:
>>> import os
>>> os.getcwd()
If your data is in a different directory (unclear from the question, but likely given the error message), then change to the directory where the data is stores:
>>> os.chdir(path_to_data_directory)

Categories