file access in debian python with h5py - python

We have an problem with python h5py in debian. The data file is in the same directory as the script file. And i'v tried to give the file test.h5 right with chmod -r and chmod 777.
Error is show up in normal user as in root access.
When we run this script:
## Libarys importeren
import wradlib
#inlezen hdf5 file en config
raw = wradlib.io.read_OPERA_hdf5("test.h5")
We get this error:
root#wxserv:/home/kbroeren# python light.py
Traceback (most recent call last):
File "light.py", line 5, in <module>
raw = wradlib.io.read_OPERA_hdf5("test.h5")
File "/usr/local/lib/python2.7/dist-packages/wradlib-0.1.1-py2.7.egg/wradlib/io.py", line 652, in read_OPERA_hdf5
f = h5py.File(fname, "r")
File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 150, in __init__
fid = make_fid(name, mode, fapl)
File "/usr/lib/python2.7/dist-packages/h5py/_hl/files.py", line 45, in make_fid
fid = h5f.open(name, h5f.ACC_RDONLY, fapl=plist)
File "h5f.pyx", line 70, in h5py.h5f.open (h5py/h5f.c:1618)
IOError: unable to open file (File accessability: Unable to open file)
root#wxserv:/home/kbroeren#
Can someone help us out with this issue ?
Thank You!

The error appears to be that you either do not have a file called test.h5 in the local directory, or you don't actually have permissions to open it. If the former, create a file called test.h5 for you to work with. But based on the error, it sounds like it may exist, but have permissions like ---------. If so, you might try running chmod u+r test.h5 and rerunning your program.

Related

Errors when i try to install pip with get-pip.py on windows 10

At the start, when i installed python, pip was installed automatically but somehow i messed with the administrator access in windows and messed it very bad,
By reading some online articles, I downloaded the get-pip.py and tried to run it with python in that same folder: python get-pip.py
But the error i get is :
Traceback (most recent call last):
File "get-pip.py", line 23484, in <module>
main()
File "get-pip.py", line 187, in main
tmpdir = tempfile.mkdtemp()
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 348, in mkdtemp
prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir)
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 117, in _sanitize_params
dir = gettempdir()
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 286, in gettempdir
tempdir = _get_default_tempdir()
File "C:\Users\Vamsi\AppData\Local\Programs\Python\Python38-32\lib\tempfile.py", line 218, in _get_default_tempdir
raise FileNotFoundError(_errno.ENOENT,
FileNotFoundError: [Errno 2] No usable temporary directory found in ['C:\\Users\\Vamsi\\AppData\\Local\\Temp', 'C:\\Users\\Vamsi\\AppData\\Local\\Temp', 'C:\\Users\\Vamsi\\AppData\\Local\\Temp', 'C:\\WINDOWS\\Temp', 'c:\\temp', 'c:\\tmp', '\\temp', '\\tmp', 'C:\\Users\\Vamsi']
In order to run get-pip.py you need make sure that you are in the directory where it is installed in. For instance i see that the dirctory you are in is C:\Users\Vamsi make sure that it is saved to this directory or cd to the right one.

Adding pip libraries in pyinstaller to create an exe file for my script

I am able to run my exe file but my scripts has multiple pip libraries for it to work. I always get this error when running my script.
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.py", line 932, in _bootstrap_inner
File "threading.py", line 870, in run
File "AIO_Bot.py", line 265, in main_function
File "cloudscraper/__init__.py", line 665, in create_scraper
File "cloudscraper/__init__.py", line 120, in __init__
File "cloudscraper/user_agent/__init__.py", line 20, in __init__
File "cloudscraper/user_agent/__init__.py", line 77, in loadUserAgent
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/8g/gkf53znx7_7405c26w344ftw0000gn/T/_MEIujM2ll/cloudscraper/user_agent/browsers.json'
Finished in 0.0 second(s)
If anyone knows how to fix this please help!
It seems that your browswers.json is expected to be found in a relative path from the "exe" (cloudscraper/user_agent) when it is not the case when it is really a exe file. You have to modify your pyinstaller build command to include that file in the package. Add
--add-data '/lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json:cloudscraper/user_agent' and it should work. (replace : with ; on Windows)
You can refer to https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-data-files for more details.
It seems your script/exe is looking for a file named "browsers.json".
Locate it and try putting it in the same folder as your created *.exe
The file is not being located because you are searching through a path that can not be opened. If your script is on the same level of the path then you would only have to do this
(browsers.json)
to fix this just exclude the directory path
mv /lib/python3.8/site-packages/cloudscraper/user_agent/browsers.json /var/folders/8g/gkf53znx7_7405c26w344ftw0000gn/T/_MEIujM2ll/cloudscraper/user_agent/
if this does not work pip install cloudscraper in terminal instead because pycharms assigniing the file to it's own enviroment

Cannot access token.json: No such file or directory Python

I'm trying to access the Gmail API via Python. Here is the instruction.
I have copied the credentials.json (I have also renamed a copy of it and called it token.json and added it into the main folder) and the quickstart.py files in the main folder. I run the quickstart.py in the cmd and using Atom IDE, but I get:
C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\_helpers.py:255: UserWarning: Cannot access token.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Traceback (most recent call last):
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\clientsecrets.py", line 121, in _loadfile
with open(filename, 'r') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'credentials.json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\HP Pavilion\Documents\Atom\Gmail\quickstart.py", line 34, in <module>
main()
File "C:\Users\HP Pavilion\Documents\Atom\Gmail\quickstart.py", line 18, in main
flow = client.flow_from_clientsecrets("credentials.json", SCOPES)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\client.py", line 2135, in flow_from_clientsecrets
cache=cache)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\clientsecrets.py", line 165, in loadfile
return _loadfile(filename)
File "C:\Users\HP Pavilion\AppData\Local\Programs\Python\Python36\lib\site-packages\oauth2client\clientsecrets.py", line 125, in _loadfile
exc.strerror, exc.errno)
oauth2client.clientsecrets.InvalidClientSecretsError: ('Error opening file', 'credentials.json', 'No such file or directory', 2)
Seems like the .json files can't be found. They are however in the same folders. I have also tried to run the code as an administrator but without any success.
I am not sure what happened to you but I run the script with either PyCharm or VS Code and it runs perfectly.
The only prerequisite (probably you skipped this step) is that you should first generate the credentials.json file, download it and put it into the same directory where you have the python script. In addition, I created an empty tokens.json file.
First, it will automatically open your default browser to indicate which Gmail account you want to specify. Next, it will output the labels of your Gmail account.
My mistake was that I right clicked on my JSON file, selected rename, then named it credentials.JSON, which made the real file name credentials.JSON.JSON.
If it is in the same location as the script, you can try:
import os
path = os.path.abspath('credentials.json')
with open(path,'r'):
//code
I had the same issue and it turned out that the problem was with the IDE I'm using (Mu 1.1.0). Once I downloaded the JSON file, renamed it, placed it in the directory to where the error was pointing to, and ran everything with cmd, it worked as it should.

python in notepad++ no such file or directory

python 2.7. Notepad++. Windows 10
I'm trying to open file like this:
sourcefile=raw_input('name of the file: ')
fhand=open(sourcefile,'r')
And it gives me this error:
Traceback (most recent call last):
File "C:\Users\Denis\Desktop\prog\python\es.py", line 135, in <module>
fhand=open(sourcefile)
IOError: [Errno 2] No such file or directory: '20.04.2016.csv'
In notepad++ i run this: C:\Python27\python.exe -i "$(FULL_CURRENT_PATH)"
Kinda new to programming but i'm guesing that I have to specify somehow path to the place where my es.py and my file is. I thought $(FULL_CURRENT_PATH) does it.
If i run my code with python or idle it works fine.
I've tried to run this program in Atom, gives same mistake. No mistakes so long as I don't work with files.

Error using Elaphe with GhostScript on Mac

I'm trying to setup elaphe on Mac. When I try generate some barcode using the terminal, with command python + /.../file.py elaphe works OK and generates the barcode correctly. But when I try to execute through web (php) I get the following error in the Apache's error logs:
Traceback (most recent call last):
File "lib/barcode_generator/generator.py", line 19, in <module>
code_39_image.save(str(random)+'.tif')
File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/Image.py", line 1406, in save
self.load()
File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/EpsImagePlugin.py", line 283, in load
self.im = Ghostscript(self.tile, self.size, self.fp)
**File "/Users/x/Library/Python/2.7/lib/python/site-packages/PIL/EpsImagePlugin.py", line 72, in Ghostscript
gs.write(s)**
If I were in Windows I would say it is a problem with the path and the program can't find the "gs.write" but in Mac I'm a rookie, I don't know if it's the same, nevertheless I've already include this 2 path:
export PATH=/Users/x/Library/Python/2.7/bin:$PATH
export PATH=/usr/local/bin:$PATH
I would appreciate can give some ideas regarding this error.
Thanks in advance.
Fixed via a symbolic link. Clearly was a PATH issue or hardcoded reference to the gs binary.
sudo ln -s /usr/local/bin/gs /usr/bin/gs

Categories

Resources