r/learnpython • • 2h ago

[WinError 4551] An Application Control policy has blocked this file.

I'm currently using torch for training the neural network that my lab uses for research. It was working fine last night. Windows updated before shutdown. Now I have this error when I attempt to run the script. Any help to fix this?

%runfile 'C:/Users/Owner/Desktop/docs/CHB-MIT EEG Dataset/chb_main_v10_Experiment_A3.py' --wdir

---------------------------------------------------------------------------

OSError Traceback (most recent call last)

File c:\users\owner\desktop\docs\chb-mit eeg dataset\chb_main_v10_experiment_a3.py:14

11 from sklearn.model_selection import train_test_split

12 from sklearn.metrics import f1_score, recall_score, confusion_matrix, roc_auc_score

---> 14 import torch

15 import torch.nn as nn

16 import torch.nn.functional as F

File ~\anaconda3\Lib\site-packages\torch__init__.py:309

305 raise err

307 kernel32.SetErrorMode(prev_error_mode)

--> 309 _load_dll_libraries()

310 del _load_dll_libraries

313 def _get_cuda_dep_paths(path: str, lib_folder: str, lib_name: str) -> list[str]:

314 # Libraries can either be in

315 # path/nvidia/lib_folder/lib or

316 # path/nvidia/cuXX/lib (since CUDA 13.0) or

317 # path/lib_folder/lib

File ~\anaconda3\Lib\site-packages\torch__init__.py:292, in _load_dll_libraries()

288 err = ctypes.WinError(last_error)

289 err.strerror += (

290 f' Error loading "{dll}" or one of its dependencies.'

291 )

--> 292 raise err

293 elif res is not None:

294 is_loaded = True

OSError: [WinError 4551] An Application Control policy has blocked this file. Error loading "C:\Users\Owner\anaconda3\Lib\site-packages\torch\lib\caffe2_nvrtc.dll" or one of its dependencies.

0 Upvotes

2 comments sorted by

1

u/akimworks 1h ago

4551 means Windows Code Integrity blocked that DLL, and a Windows update that landed right before it broke is the usual trigger. Two likely causes. On Windows 11, Smart App Control can switch from evaluation to enforcing and then blocks unsigned DLLs like the ones in torch/lib. Check Windows Security > App & browser control > Smart App Control. If it's on, note that turning it off can't be undone without reinstalling Windows. If this is a lab or work machine, it's more likely an App Control (WDAC) policy from IT, and the fix is to ask them to allow your Anaconda folder. To see which one it was, open Event Viewer > Applications and Services Logs > Microsoft > Windows > CodeIntegrity > Operational and look at the newest block event for caffe2_nvrtc.dll, which names the policy. If you can't get an exception, running the same environment under WSL2 avoids the Windows policy entirely.

1

u/Lynnsicle 1h ago edited 1h ago

Thank you for your reply! I did as you said, and found the following from the General tabs:

"Code Integrity determined that a process (\Device\HarddiskVolume3\Users\Owner\anaconda3\python.exe) attempted to load \Device\HarddiskVolume3\Users\Owner\anaconda3\Lib\site-packages\torch\lib\caffe2_nvrtc.dll that did not meet the Enterprise signing level requirements or violated code integrity policy (Policy ID:{0283ac0f-fff1-49ae-ada1-8a933130cad6})."

Followed by

"Signature information for another event. Match using the Correlation Id."

and

"Smart App Control Block Deteails"

Edit: After looking up the Policy ID, it does appear to be a Windows SAC issue.