工作电脑中pandas/numpy等Python包被组策略(AppLocker)阻止的解决方案咨询
First, let's break down why this is happening: AppLocker restricts execution of specific file types (like .pyd Python compiled extensions or .dll files), and pandas/numpy rely heavily on these binary components—unlike pypyodbc which might be pure Python or use already-allowed binaries.
Here's exactly what you need to ask your IT team to unblock, no need to open up the entire site-packages folder:
1. Use Windows Event Viewer to get the EXACT blocked file paths (most reliable method)
This is the best way to avoid guesswork:
- Run your failing script (e.g.,
import pandas) - Open Event Viewer → Navigate to
Applications and Services Logs > Microsoft > Windows > AppLocker > EXE and DLL - Look for events with Event ID 8004—this will explicitly list the full path of the file that was blocked by AppLocker. Copy these paths directly and send them to IT.
2. If you can't access Event Viewer, specify these targeted paths
If you need to pre-emptively list the likely culprits, focus on the compiled binary files in pandas and numpy's directories:
- For numpy: Unblock all
.pydand.dllfiles under thenumpy/coreandnumpy/libsubdirectories. Example path rules for AppLocker:%USERPROFILE%\AppData\Local\Programs\Python\PythonXX\Lib\site-packages\numpy\**\*.pyd%USERPROFILE%\AppData\Local\Programs\Python\PythonXX\Lib\site-packages\numpy\**\*.dll
- For pandas: Unblock all
.pydfiles under thepandas/_libssubdirectory. Example path rules:%USERPROFILE%\AppData\Local\Programs\Python\PythonXX\Lib\site-packages\pandas\**\*.pyd
- Note: Replace
PythonXXwith your Python version (e.g.,Python310) and adjust the base path if you're using a system-wide Python install (e.g.,C:\Program Files\PythonXX\Lib\site-packages\...instead of the user profile path).
3. Why this works instead of unblocking all site-packages
AppLocker operates on file execution rules—pandas and numpy use compiled binary extensions (.pyd) that act like mini-executables, which are being blocked. By targeting only these specific subdirectories and file types, you minimize the security exposure while solving your issue.
内容的提问来源于stack exchange,提问作者acausedelle

