I'm trying to make a program with python that will be able to analyse some game event's statistics with OCR and make a summary of a player/group's performance. I'm really new to Python, and I had multiple Python (2 - 3) installed before because I was trying it a little bit years ago. So I uninstalled everything and reinstalled the latest Python 3 to the default/recommended installation (AppData) path.
def ocr_core(img):
text = pytesseract.image_to_string(img)
return text
Error:
Exception has occurred: PermissionError
[WinError 5] Access is denied
File "G:\PythonProjects\NewWorldWarStats.py", line 7, in ocr_core
text = pytesseract.image_to_string(img)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "G:\PythonProjects\NewWorldWarStats.py", line 25, in <module>
print(ocr_core(img))
^^^^^^^^^^^^^
PermissionError: [WinError 5] Access is denied
I'm trying pytesseract (same permission error with other OCR library) and cv2 to do the task but it gives me permission error no matter if I edit permission to that folder, run the Visual Studio Core as admin. I was also tried to run the project on other drives, nothing worked yet. Any ideas?
Okay, I found out what was the problem. I had to put the whole "tesseract.exe" path, not just its main folder, altho most of the guides only put the folder, not the whole executable path.
So for me, this was the right one:
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\Dany\AppData\Local\Programs\Tesseract-OCR\tesseract.exe'
Thanks for the help.
Related
I am trying to run a python code that performs XGboosting and I wanted it to run parallely to take less time in building a model. But I am facing this issue while running a code.
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\<<username>>\\AppData\\Local\\Temp\\joblib_memmapping_folder_85680_9566857635\\85680-1746225537432-968de5958f0642829c37f0f09f0e8b00.pkl'
I have even tried running the anaconda prompt as an administrator. But it is of no use. As a workaround I have also tried what is suggested in https://github.com/joblib/joblib/issues/806 but even then I am facing the same issue.
Could you please advice?
I'm trying to download a CSV file from Dropbox using their library in Python, but I'm having quite the issue trying to get the permissions needed to be able to actually get it into the computer.
The error message that I'm getting in any case is this:
PermissionError: [Errno 13] Permission denied: 'my_directory'
So I've tried the only two solutions I'm finding as I investigate: 1) change the mode of the directory to '0o777' using os.chmod(), and 2) running things as an admin. But even with both, I'm still not getting rights to write the file to my local computer. It might also be worth noting that the name of the file and the directory I'm trying to write it to do not have the same name.
import os
import dropbox
local_dir = 'absolute_path_to_directory'
os.chmod(local_dir, 0o777)
dbx = dropbox.Dropbox('my_token_here')
dbx.files_download_to_file(local_dir, 'path_to_file_in_dropbox')
I would think that running this kind of program as an administrator and having changed the directory permissions, I would have permissions to actually download the file to it. But I'm still getting the PermissionError I noted above.
Any help or insight into what might be causing the issue would be much appreciated.
According to the documentation chmod you can only set the read-only flag all other bits are ignored. However, this might not be the problem.
Looking at the dropbox forum, it looks like you might be missing a '/' along with the filename, and not just the directory.
dbx.files_download_to_file(j, '/'+ j)
According to Greg
You do need to use the full path when specifying the file you want to download. Using files_list_folder and files_list_folder_continue will give you every entry, and you can get the full path from the returned (File)Metadata.path_lower. (I.e., use entry.path_lower instead of '/'+entry.name.)
I've been tinkering with the os module for a few days encountered this error. Can't seem to fix it.
Here is an example:
import os
os.chdir('C:\\Users\\User\\Desktop')
os.rename('odin', 'ddin')
print (os.listdir())
And this is the error:
PermissionError: [WinError 5] Access is denied: 'odin' -> 'ddin'
Any help?
you are running your python program from an user that does not have permissions to change the specific file name ' try running from another user or change the file permissions to allow writing to your user.
First, try running the same program in IDLE with administrator privileges.
Second, There is chance that your anti-virus software is blocking your python script so try disabling antivirus.
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.
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'))