I have a small application that I have made. It basically copies a zip file from a network location to the computer that is running the application, unzips it in a folder and then creates a shortcut on the desktop.
Most of the time (I'd say about 80%) it works as intended. The other 20% of the time the stack trace it says it cannot create a file. It is always the same (_bz2.pyd). If I close it and run it again it works fine after this happens.
Anyone have any ideas of what is going on? Here is the code that extracts the file. I've even made the script try and extract the file, check if it worked, try and extract the file again. This hasn't solved the issue:
print ('uncompressing databases. This takes a few minutes')
# file_name = settings.working_folder + r'\UAT_Databases.zip'
temp_name = settings_dict['working_folder'] + settings_dict['file_name']
zip_ref = zipfile.ZipFile(temp_name, 'r')
zip_ref.extractall(settings_dict['install_folder'])
zip_ref.close()
logr.info('unzipped databases')
Here is the stack trace:
Traceback (most recent call last):
File "temp_installer.py", line 141, in unzip_databases
File "zipfile.py", line 1347, in extractall
File "zipfile.py", line 1335, in extract
File "zipfile.py", line 1398, in _extract_member
PermissionError: [Errno 13] Permission denied: 'C:\\TempApps\\Temp_application\\_bz2.pyd'
2020-03-03 11:36:25,697 : ERROR : __main__ : could not unzip databases
Traceback (most recent call last):
File "temp_installer.py", line 141, in unzip_databases
File "zipfile.py", line 1347, in extractall
File "zipfile.py", line 1335, in extract
File "zipfile.py", line 1398, in _extract_member
PermissionError: [Errno 13] Permission denied: 'C:\\TempApps\\Temp_application\\_bz2.pyd'
Related
Premise
I'm trying to convert some PDF to images via pdf2image and poppler, to then run some computervision tasks on.
The conversion itsself works fine.
However, the conversion creates some artifacts for each page in the pdf as it is being converted, which I would like to be deleted at the end of the function. To facilitate this, I am using tempfile.TemporaryDirectory(). The function looks as follow:
with tempfile.TemporaryDirectory() as path:
images_from_path: [Image] = convert_from_path(
os.path.join(path_superfolder, "calibration_target.pdf"),
size=(2480, 3508),
output_folder=path, poppler_path=r'E:\poppler-22.04.0\Library\bin')
if len(images_from_path) >= page:
images_from_path[page - 1].save(os.path.join(path_superfolder, "result.jpg"))
Problem
The trouble is, that the program always crashes with the following errors, after transforming the PDF and writing the required image to a file.
Traceback (most recent call last):
File "C:\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file, because it is being used by another process: 'C:\\Users\\tobia\\AppData\\Local\\Temp\\tmp24c4bmzv\\bd76d834-672e-49fc-ac30-7751b7b660d0-01.ppm'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\tempfile.py", line 843, in onerror
_os.unlink(path)
PermissionError: [WinError 32] The process cannot access the file, because it is being used by another process: 'C:\\Users\\tobia\\AppData\\Local\\Temp\\tmp24c4bmzv\\bd76d834-672e-49fc-ac30-7751b7b660d0-01.ppm'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python310\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "E:\PyCharm 2022.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "E:\PyCharm 2022.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:\Dokumente\Uni\Informatik\BA_Thesis\tumexam-scheduling-codebase\generate_data.py", line 393, in <module>
extract_calibration_page_as_image_from_pdf()
File "D:\Dokumente\Uni\Informatik\BA_Thesis\tumexam-scheduling-codebase\generate_data.py", line 190, in extract_calibration_page_as_image_from_pdf
tmp_dir.cleanup()
File "C:\Python310\lib\tempfile.py", line 873, in cleanup
self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
File "C:\Python310\lib\tempfile.py", line 855, in _rmtree
_shutil.rmtree(name, onerror=onerror)
File "C:\Python310\lib\shutil.py", line 749, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 619, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Python310\lib\tempfile.py", line 846, in onerror
cls._rmtree(path, ignore_errors=ignore_errors)
File "C:\Python310\lib\tempfile.py", line 855, in _rmtree
_shutil.rmtree(name, onerror=onerror)
File "C:\Python310\lib\shutil.py", line 749, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Python310\lib\shutil.py", line 600, in _rmtree_unsafe
onerror(os.scandir, path, sys.exc_info())
File "C:\Python310\lib\shutil.py", line 597, in _rmtree_unsafe
with os.scandir(path) as scandir_it:
NotADirectoryError: [WinError 267] Directory name invalid: 'C:\\Users\\tobia\\AppData\\Local\\Temp\\tmp24c4bmzv\\bd76d834-672e-49fc-ac30-7751b7b660d0-01.ppm'
When stepping through the cleanup routine, everything seems fine, the path is correct and it starts deleting files, until at some point the internal path variable gets jumbled up and the routine crashes, because obviously a file is not a directory. To me it seems like a race condition is causing problems here.
What I have already tried
Rewriting the function to not use with and instead explicitly call the routine with tmp_dir.cleanup()
Just creating the directory without populating it with the conversion artifacts. The cleanup works in this case.
The documentation for tempfile mentions Permission errors occuring when files are open. The files are however only used in this function and if this is what is causing the error, I am unsure where the files are still opened or which function is causing this. My suspicion of course would be the conversion function.
While experimenting some more and writing this question, I found a working solution:
with tempfile.TemporaryDirectory() as path:
images_from_path: [Image] = convert_from_path(
os.path.join(path_superfolder, f"calibration_target_{exam_type}.pdf"),
size=(2480, 3508),
output_folder=path, poppler_path=r'E:\poppler-22.04.0\Library\bin')
if len(images_from_path) >= page:
images_from_path[page - 1].save(os.path.join(path_superfolder, "result.jpg"))
images_from_path = []
It seems that somehow, the routine had trouble cleaning up, because the converted images, are actually the artifacts created by pdf2image and were still being held by my data structure. Resetting the data structure, before implicitly initiating the cleanup fixed the issue.
If there is a better way of tackling this issue, please do not hesitate to inform me.
I have never used python before and I want to build a project I found on github but I have not solved a problem there for 2 hours. I don't think it's a problem that I've installed all the packages individually. I've applied all the necessary documents that he narrates, but when I run the following command, I get an error How can I solve this error?
https://github.com/tsurumeso/vocal-remover
Run
python inference.py --input C:\Users\Berkay\Desktop\vocal-remover
error output
PS C:\Users\Berkay\Desktop\vocal-remover> python inference.py --input C:\Users\Berkay\Desktop\vocal-remover loading model... done
C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\librosa\core\audio.py:146: UserWarning: PySoundFile failed. Trying audioread instead.
warnings.warn('PySoundFile failed. Trying audioread instead.')
loading wave source... Traceback (most recent call last):
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\librosa\core\audio.py", line 129, in load
with sf.SoundFile(path) as sf_desc:
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\soundfile.py", line 629, in __init__
self._file = self._open(file, mode_int, closefd)
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\soundfile.py", line 1184, in _open
"Error opening {0!r}: ".format(self.name))
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\soundfile.py", line 1357, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'C:\\Users\\Berkay\\Desktop\\vocal-remover': System error.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "inference.py", line 39, in <module>
args.input, args.sr, False, dtype=np.float32, res_type='kaiser_fast')
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\librosa\core\audio.py", line 147, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\librosa\core\audio.py", line 171, in __audioread_load
with audioread.audio_open(path) as input_file:
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\audioread\__init__.py", line 111, in audio_open
return BackendClass(path)
File "C:\Users\Berkay\AppData\Local\Programs\Python\Python37\lib\site-packages\audioread\rawread.py", line 62, in __init__
self._fh = open(filename, 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Berkay\\Desktop\\vocal-remover'
I found the solution to the problem.
False
python inference.py --input C:\Users\Berkay\Desktop\vocal-remover
That's right
python inference.py --input C:\Users\Berkay\Desktop\vocal-remover\music.mp3
I think the problem is that your input is a directory, while I bet it should be some audio file. You should do:
inference.py --input path/to/your/audio.wav
I'm new to Python and self-teaching myself neural networks from this http://neuralnetworksanddeeplearning.com/chap1.html and I'm having trouble importing the files that I've downloaded for the exercises. This is the error message I keep getting:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
File "mnist_loader.py", line 68, in load_data_wrapper
File "mnist_loader.py", line 42, in load_data
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gzip.py", line 34, in open
return GzipFile(filename, mode, compresslevel)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gzip.py", line 94, in __init__
fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
IOError: [Errno 2] No such file or directory: '../data/mnist.pkl.gz'
I've looked around and tried this:
>>> open('Users/bryanjordan/Documents/neural-networks-and-deep-learning-master/mnist.pkl')
but get this error:
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
open('Users/bryanjordan/Documents/neural-networks-and-deep-learning-master/mnist.pkl')
IOError: [Errno 2] No such file or directory: 'Users/bryanjordan/Documents/neural-networks-and-deep-learning-master/mnist.pkl'
I also meet this question. And I find the solution to solve this problem.
If you run the code in the python console, please first use "cd" into the "/src" folder, and run the code.
If you run the code in a python file (like me), you should put the file into the "/src" folder.
It will be solved. The only reason is that the relative path. You should stand in the right place.
Hope to help you.
I wrote this program to move videos from my download folder to different destination folders.
import os
import shutil
import sys
folder = []
highlight = ['highlights','goals','skills']
comedy_word = ['comedy', 'acapella','seyilaw','basketmouth','basket mouth','bovi','gordons','buchi','rhythm unplugged','elenu','seyi law','akpororo','emmaohmygod','klint','shakara','funnybone','igodye','i go die','i go dye','igodye','whalemouth','whale mouth','daniel']
series_word = ['lost', 'thrones', 'vampire', 'originals', 'ship', '']
grub_word = ['programming', 'python', 'linux','exploit','hack']
for i in os.listdir('C:\\Users\\Afro\\Downloads\\Video'):
folder.append(i.lower())
def tv_series(series):
for serie in series:
if 'ship' in serie:
shutil.move(serie, 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\The Last Ship\\The Last Ship 3\\' )
print(serie[:-3] +': Moved!')
elif 'lost' in serie:
shutil.move(serie, 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\Lost\\s2\\' )
print(serie[:-3] +': Moved!')
The file's name is arrange.py and the program throws a filenotfound error when arrange.py is not in the "C:\Users\Afro\Downloads\Video" folder. Is it possible to make the program run in any folder?
Thanks
Here's the error it throws.
Traceback (most recent call last):
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 538, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'lost - s02e08 (o2tvseries.com).mp4' -> 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\Lost\\s2\\lost - s02e08 (o2tvseries.com).mp4'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Afro\Desktop\Arrange.py", line 77, in <module>
start(folder)
File "C:\Users\Afro\Desktop\Arrange.py", line 65, in start
tv_series(folder)
File "C:\Users\Afro\Desktop\Arrange.py", line 22, in tv_series
shutil.move(serie, 'C:\\Users\\Afro\\Desktop\\Movies\\Series\\Lost\\s2\\' )
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 552, in move
copy_function(src, real_dst)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 251, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Afro\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 114, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'lost - s02e08 (o2tvseries.com).mp4'
You call shutil.move specifying the reference point incorrectly. In your loop that gathers the files, you should use os.path.join('C:\\Users\\Afro\\Downloads\\Video', i) and put that in your list instead. Otherwise it's all relative paths, hence the FileNotFound error.
You could also change the working directory. This would make the script behave as if it was in a different folder. This can have some unintended consequences, so be careful. Details here.
Hope this helps!
I am trying to download a link and place it in the downloads folder, however I get a permission error. I am an admin user on the computer and I also ran it in administrator mode. Still I get the same error.
Here is the code I use:
urllib.urlretrieve(link, r"C:\Users\%s\Downloads" % (user))
Here is the error I get:
Traceback (most recent call last):
File "C:\Users\Grant\Desktop\FTB Server Updater\FTB Updater_v1.0.py", line 28, in <module>
getNewServer(link)
File "C:\Users\Grant\Desktop\FTB Server Updater\FTB Updater_v1.0.py", line 22, i getNewServer
urllib.urlretrieve(lynk, r"C:\Users\%s\Downloads" % (user))
File "C:\Python27\lib\urllib.py", line 94, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
File "C:\Python27\lib\urllib.py", line 244, in retrieve
tfp = open(filename, 'wb')
IOError: [Errno 13] Permission denied: 'C:\\Users\\Grant\\Downloads'
Shouldn't urllib.urlretrieve(link, r"C:\Users\%s\Downloads" % (user)) be urllib.urlretrieve(link, r"C:\Users\%s\Downloads\SAVE_FILE_NAME" % (user))? You are trying to overwrite the Downloads directory, which I am not sure Windows would allow. It might be possible in unix if you have permissions, but Windows might stop you from doing that!