I am using netCDF4 and python 3.4.
I run the following line of code in order to start writing a new netCDF file that I will be filling with data later in my code following netcdf4 documentation. I however keep getting this error...
File "netCDF4.pyx", line 1466, in netCDF4.Dataset.__init__ (netCDF4.c:19692) RuntimeError: Permission denied
from netCDF4 import Dataset
rootgrp = Dataset('test.nc', 'w', format='NETCDF4')
Any help will be most appreciated.
The "Permission denied" part of the error leads me to believe you don't have permissions to write to the current directory (wherever you are when you run your script).
Check your permissions and/or try giving a full path to put the file in a directory you know you can write to.
dataset.close()
or close ide and delete file 'netCDF4.pyx'
maybe a file exist there, so can't write it.
In my case, this error arises when I am running python by crontab.
The solution is to add following line at the beginning of crontab file.
HDF5_USE_FILE_LOCKING=FALSE
Related
This throws file not found error, I guess because of the path argument. The path argument is needed for the clemb.exe, which is a batch runner for the stream. Even when I try to run it without the path arguments I get access dennied. I am currently running this from pycharm but I want to compile to a binary and ship to customer.
Any suggestions how to bypass the file not found error and the access denied issue?
import sys
import subprocess
subprocess.call([r'"C:\Program Files\IBM\SPSS\Modeler\18.2\bin\clemb.exe -stream path\to\spss\modeller\stream\stream.str"'])
I am using Python 3.7
I guess
subprocess.call([r'C:\Program Files\IBM\SPSS\Modeler\18.2\bin\clemb.exe', '-stream', r'path\to\spss\modeller\stream\stream.str'])
should be more clear and working.
This code
from PIL import ImageGrab, Image
im = ImageGrab.grab()
im.save(r'D:/MyFilesForProject/Network/screen.jpg')
cause this error
Traceback (most recent call last):
File "G:/PycharmProjects/2.7NetworkExersice/Screenshot.py", line 4, in
<module>
im.save(r'D:\MyFilesForProject\Network\screen.jpg')
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1676, in save
fp = builtins.open(fp, "wb")
IOError: [Errno 13] Permission denied:
'D:\\MyFilesForProject\\Network\\screen.jpg'
I tried to find a solution in the whole internet and I did not find anything working. In order to avoid repetitive advice: yes, I allowed reading and writing the folder in the properties and tried to save it in another place. I really hope for your help. Thank you in advance.
THere is a problem with Python having Permission to write to that drive.
Try to run Python as an Admin:
From commandline:
runas.exe /user:administrator "C:\Python27\python.exe Screenshot.py"
I managed to replicate your error by attempting to save to folder that did not have write permissions.
This is how I fixed the error:
Right click on the folder you wish to save to.
Click properties at the bottom of the list
Go to the security tab
Click the Edit button next to To change permissions, click Edit
make sure the write section has a tick in the Allow column for the user you are logged in as. If this is not a private folder or a security risk you can allow for everyone
One other thing I noted was I had the error from the updated fix
File "C:\Anaconda3\lib\site-packages\PIL\Image.py", line 1725, in save
fp = builtins.open(filename, "w+b")
note the w+b whereas in your traceback you have wb
This could be due to using an outdated version of PIL..
Try uninstalling PIL via PIP and then reinstalling the latest version with
pip install pil
One other difference is that I ran this on Python 3.6 not 2.7 like yourself.
I am a complete novice in python and I have already searched several entries in stackoverflow to help me but I am still struggling. I feel that this should be very easy to do. Your help is greatly appreciated.
I have the following script: https://github.com/openxc/openxc-data-tools/blob/master/tracecsv.py
My goal is to run it on a python shell on window xp to convert Json file like (http://openxcplatform.com.s3.amazonaws.com/traces/nyc/downtown-crosstown.json) in a format that can be saved as csv.
So far, when I run the following code on my python shell (after changing the directory to where my files are located) I get an error and I am not able to have the output csv I am expected:
Here are what I enter in the command shell and the error:
python tracecsv.py downtown-crosstown.json output_file_name
SyntaxError: invalid syntax
tracecsv.py downtown-crosstown.json output_file_name
SyntaxError: invalid syntax
My understanding is that tracecsv.py read the script saved in my specified directory and the next two string specify the input file to be used in the code (as sys.argv1 and sys.argv2). I am expecting a csv file to be saved in my specify directory with my json file converted in excel structure and ready for analysis.
Thank you!
When I try to create a new file in PyScriptor using the following code, it works perfectly with no errors but when I use the same code outside of PyScriptor for example in the IDE, it just flashes an error and closes.
file = open("file.txt", "w")
file.write("hello")
file.close()
I cannot get the errors because the error message lasts for less than a second before the Interpreter closes.
Help to figure out why this happens and how to fix it is appreciated.
I am using Python version 2.5.3.0 on windows 7 if this helps.
[EDIT]
Thanks to kirbyfan64sos and JAB for helping me get the errors. It turns out that Python does not have permission to open any file at all (r, w, a etc) yet Pyscriptor has all these permissions so the question still remains: why are they be different and how do i fix them?
I know that it is not the permissions of the file itself otherwise it would not work in Pyscriptor.
[ERROR CODE]
Traceback (most recent call last):
File "IDE File test.py", line 1, in <module>
file = open("file.txt", "w")
IOError: [Errno 13] Permission denied: "file.txt"
Use "w" instead of "W". "W" is an invalid file mode. Also, file.close should be file.close(), as file.close will just return the file object's close method and won't actually call it.
Note that if you start the interpreter from inside the command shell, the shell won't close when an error is raised so you'll be able to see it there. The same applies to using IDLE.
Chances are the permissions of wherever your IDE is running in are not writable by you.
To check:
import os
print(os.path.abspath(os.curdir))
I'm quite certain that you'll find the current path will be different depending on which IDE you run from. Most IDEs have a setting for which path you'll start at. You can also get around that by using os.chdir to change to your home directory (or giving an absolute path to open(), e.g. open('/home/wayne/test.txt', 'w'))
I am placing this code into IDLE:
f = open('/Users/alex/Documents/URM8/health.tdf')
I don't understand why I am unable to open it. I get the error:
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
f = open('/Users/alex/Documents/URM8/health.tdf')
IOError: [Errno 2] No such file or directory: '/Users/alex/Documents/URM8/health.tdf'
Of course usually the problem is filename. I have checked it lots of times and it is correct.
I 'unlocked' the file (I'm using Mac OSX). Also set write access to Everyone in Mac OSX.
Do i need to set permissions in Bash?
Really appreciate someone telling me what I'm doing wrong!
/Users/alex/Documents/URM8/health.tdf cannot be opened because it's not there; the Mac OS UI hides the .txt extension. open('/Users/alex/Documents/URM8/health.tdf.txt') works fine.
The problem is not the permissions. If it were, the error message would be different. Is some component of the path a Mac alias to a directory, rather than a directory? If so, Python won't follow it, and will give that error.
Try individual parts of the pathname to see exactly which directory or file Python can't find. You could do this simply using cd in the shell.
Are you trying to use a relative path? The leading '/' could be a problem.
You don't specifically define the file mode ("r", "w", etc.) in your open call, you may want to reconsider this.
You could try ls -l on the file to get its permissions.
chmod u+rw <FILE> should give you access.