Docx file is locked for editing - python

I am using the python-docx library to make docx files and then later print them to PDF's. Normally, i use os.remove(file_path)
to get rid of the docx files created during the process. If I do not destroy these files and then run the script again, I get an error because the file is locked for editing. I'm trying to understand what is happening here and what the proper protocol is for dealing with these intermediate files.
Any help would be appreciated.
The script generates a docx file called Example.docx and then converts the docx file to a pdf. If I destroy the docx file, I can run the script again with no problem. If I do not destroy Example.docx, I get this error: PermissionError: [Errno 13] Permission denied: 'Example.docx'
I'm trying to understand why this is occurring.

Related

Pytesseract Error - no such file or directory Error during processing

I am computing quite a simple Image to text using Pytesseract in Python. However, I keep having this error
pytesseract.pytesseract.TesseractError: (1, 'Tesseract Open Source OCR
Engine v5.0.0-alpha.20200328 with Leptonica Error, cannot read input
file C:\code\img: No such file or directory Error during
processing.')
I try to place both my image and python files in the same folder but the error is still there. Is there a way to fix this?
It's a permission issue of OS, not pytesseract.
The root cause is that there is no permission for reading that file.
In my project in Ubuntu 20, I moved that folder to another directory and everything is okay.
You can try the same at https://askubuntu.com/questions/1046890/libreoffice-cant-access-tmp-files-in-18-04.

Import a .dat file in spyder?

I am supposed to access a .dat file to perform some code. The directions that I am following are telling me to make a subdirectory for the main code then make another subdirectory for the .dat file. However, I am not entirely sure how to do that. Any help would be greatly appreciated!
So far, everything I have tried has given me the following error message:
FileNotFoundError: [Errno 2] No such file or directory

pandas df to_csv freezes when using pyinstaller to save the df in the exe directory

I am trying to save the output dataframe to a csv file while using pyinstaller to create an exe, but my code freezes and generate "[Errno 13] Permission denied: '.\Output.csv' " error. My question is. what wrong using df.to_csv to save the output file in the same exe directory ?
Thanks in adcance
Look, if you use Innodb compiler then you will face a problem of permission denied error in the setup. So , I have tried to solve that by using temporary file but It is getting deleted after generation. But if you really want to solve this problem then use xlsxwriter and save it to a specific file location.

How can i open a folder using python?

I've tried reading through the other answered similar questions, yet still can't find what I'm doing wrong.
file=open("Crawl","r")
cont=file.read()
file.close
print(cont)
It's as simple as that. Both the folder and python are on the desktop which explains why there isn't a directory to it. I did try opening .txt and .png files and that did work, but it seems I can't open folders?
PermissionError: [Errno 13] Permission denied: 'Crawl'
You are getting this error because you are trying to open "Crawl" as a file. It's a folder, and you can't treat a Windows folder as if it were a file.

"IOError [Errno 13] Permisson denied" when copy a file on Windows

I wrote a program that will copy a file called a.exe to C:/Windows/, then I pack it to exe with PyInstaller, and rename the exe file to a.exe. When I run the exe file, it output IOError [Errno 13] Permisson denied: 'C:/Windows/a.exe', but the file a.exe was copied to the directory C:/Windows. Then I ran it as the Administrator, it happened again...
At first, I copy the file with shututil.copy, then I wrote a function myself(open a.exe, create a.exe under C:/Windows, read a.exe 's content and write to C:/Windows/a.exe, close all), but it doesn't help...Any ideas?
Check if a.exe has read-only attribute. shutil.copy raises "Permission denied" error when it is called to overwrite existing file with read-only attribute set
Apparently you're trying to execute a file that moves itself to a different place ... I guess that cannot work.
Can you copy files that are open in Windows? I have a vague memory that you can't, and the file will be open while you execute it.
Is it really being copied? It doesn't exist there before copying? Did it copy the whole file?

Categories