Access denied error when running TotalSegmentator
Hi everyone, I was previously able to run the total segmentator but today I am getting an access denied error in the early stages of running.
The final message I get is
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\------\\AppData\\Local\\Temp\\tmp3sifet_4\\dicom
All of this code worked perfectly yesterday but today its failing. Ive checked that I have access to that folder and I tried to execute the code under an administrator account but I get the same error.
Any clues?
the full trace back is:
Traceback (most recent call last):
File "C:\Program Files\Python312\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Program Files\Python312\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "c:\Users\-------\OneDrive -------\Research\Splenic Flexure\CT_segment.py", line 8, in foo
totalsegmentator('451617//CT','451617//segments',fast=True)
File "C:\Users\-------\OneDrive -------\Research\Splenic Flexure\.venv\Lib\site-packages\totalsegmentator\python_api.py", line 467, in totalsegmentator
seg_img, ct_img, stats = nnUNet_predict_image(input, output, task_id, model=model, folds=folds,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\-------\OneDrive -------t\Research\Splenic Flexure\.venv\Lib\site-packages\totalsegmentator\nnunet.py", line 341, in nnUNet_predict_image
dcm_to_nifti(file_in, tmp_dir / "dcm" / "converted_dcm.nii.gz", tmp_dir, verbose=verbose)
File "C:\Users\-------\OneDrive -------\Research\Splenic Flexure\.venv\Lib\site-packages\totalsegmentator\dicom_io.py", line 131, in dcm_to_nifti
dicom2nifti.dicom_series_to_nifti(input_path, output_path, reorient_nifti=True)
File "C:\Users\-------0\OneDrive -------\Research\Splenic Flexure\.venv\Lib\site-packages\dicom2nifti\convert_dicom.py", line 86, in dicom_series_to_nifti
shutil.rmtree(temp_directory)
File "C:\Program Files\Python312\Lib\shutil.py", line 781, in rmtree
return _rmtree_unsafe(path, onexc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\shutil.py", line 629, in _rmtree_unsafe
onexc(os.rmdir, fullname, err)
File "C:\Program Files\Python312\Lib\shutil.py", line 627, in _rmtree_unsafe
os.rmdir(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\-------\\AppData\\Local\\Temp\\tmp3sifet_4\\dicom'
Unfortunately I have no idea what the reason might be.
run as admin when open pycharm may help
@nforwood Have you solved your problem? I also encountered a similar problem when running on Windows.
Not an actual fix to the problem, but the following workaround should work:
- Open the file convert_dicom.py (your path from above: C:\Users-------0\OneDrive -------\Research\Splenic Flexure.venv\Lib\site-packages\dicom2nifti\convert_dicom.py)
- Search for "rmtree" and remove the whole "finally" block where it calls
shutil.rmtree(temp_directory)
finally:
# remove the copied data
shutil.rmtree(temp_directory)
- Run it again.
Your TEMP folder will eventually fill up though, so you may want to clean it manually.
Thank you for your reply! I tried to remove the read-only attribute of the source folder, and then it worked properly.
程辉 @.***
签名由 网易灵犀办公 定制
Original: From:Matias Lavik @.>Date:2025-03-13 04:18:55(中国 (GMT+08:00))To:wasserth/TotalSegmentator @.>Cc:chzuhuich @.> , Comment @.>Subject:Re: [wasserth/TotalSegmentator] Access denied error when running TotalSegmentator (Issue #391)Not an actual fix to the problem, but the following workaround should work: Open the file convert_dicom.py (your path from above: C:\Users-------0\OneDrive -------\Research\Splenic Flexure.venv\Lib\site-packages\dicom2nifti\convert_dicom.py) Search for "rmtree" and remove the whole "finally" block where it calls shutil.rmtree(temp_directory) finally: # remove the copied data shutil.rmtree(temp_directory) Run it again.Your TEMP folder will eventually fill up though, so you may want to clean it manually. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.> mlavik1 left a comment (wasserth/TotalSegmentator#391) Not an actual fix to the problem, but the following workaround should work: Open the file convert_dicom.py (your path from above: C:\Users-------0\OneDrive -------\Research\Splenic Flexure.venv\Lib\site-packages\dicom2nifti\convert_dicom.py) Search for "rmtree" and remove the whole "finally" block where it calls shutil.rmtree(temp_directory) finally: # remove the copied data shutil.rmtree(temp_directory) Run it again.Your TEMP folder will eventually fill up though, so you may want to clean it manually. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>
不用谢!
By the way, which folder did you change the read-only attribute for? The folder containing the dataset?
@chzuhuich
我看你回复的是“不用谢”,不清楚你平时是否用中文(我是中国人) The folder contains the dataset(dicom files)
程辉 @.***
签名由 网易灵犀办公 定制
Original: From:Matias Lavik @.>Date:2025-03-18 04:33:57(中国 (GMT+08:00))To:wasserth/TotalSegmentator @.>Cc:chzuhuich @.> , Mention @.>Subject:Re: [wasserth/TotalSegmentator] Access denied error when running TotalSegmentator (Issue #391)不用谢! By the way, which folder did you change the read-only attribute for? The folder containing the dataset? @chzuhuich — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.> mlavik1 left a comment (wasserth/TotalSegmentator#391) 不用谢! By the way, which folder did you change the read-only attribute for? The folder containing the dataset? @chzuhuich — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.>
Ok, thanks! The folder I was loading from was not set to read-only though, but I'll test again. I will probably need to look more into this next week, since it's a problem that affects my client/colleague. I'll share here if I figure out something.
(我是挪威人。会说一点中文,但我的中文水平不高。)
Looking forward to your sharing! By the way, based on TotalSegmentor, what research do you mainly focus on?
程辉 @.***
签名由 网易灵犀办公 定制
Original: From:Matias Lavik @.>Date:2025-03-21 21:57:21(中国 (GMT+08:00))To:wasserth/TotalSegmentator @.>Cc:chzuhuich @.> , Mention @.>Subject:Re: [wasserth/TotalSegmentator] Access denied error when running TotalSegmentator (Issue #391)Ok, thanks! The folder I was loading from was not set to read-only though, but I'll test again. I will probably need to look more into this next week, since it's a problem that affects my client/colleague. I'll share here if I figure out something. (我是挪威人。会说一点中文,但我的中文水平不高。) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.> mlavik1 left a comment (wasserth/TotalSegmentator#391) Ok, thanks! The folder I was loading from was not set to read-only though, but I'll test again. I will probably need to look more into this next week, since it's a problem that affects my client/colleague. I'll share here if I figure out something. (我是挪威人。会说一点中文,但我的中文水平不高。) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.>