Traceback (most recent call last): File "D:\py\lib\site-packages\pytesseract\pytesseract.py", line 255, in run_tesseract proc = subprocess.Popen(cmd_args, **subprocess_args()) File "D:\Python37\lib\subprocess.py", line 800, in init restore_signals, start_new_session) File "D:\Python37\lib\subprocess.py", line 1207, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\pythonProject\test3.py", line 21, in <module> subtitle_text = pytesseract.image_to_string(subtitle_region, config=config) File "D:\py\lib\site-packages\pytesseract\pytesseract.py", line 427, in image_to_string }output_type File "D:\py\lib\site-packages\pytesseract\pytesseract.py", line 426, in <lambda> Output.STRING: lambda: run_and_get_output(*args), File "D:\py\lib\site-packages\pytesseract\pytesseract.py", line 288, in run_and_get_output run_tesseract(**kwargs) File "D:\py\lib\site-packages\pytesseract\pytesseract.py", line 260, in run_tesseract raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.刚刚你修改后报这个错误
时间: 2023-08-07 21:02:31 浏览: 346
这个错误提示是说找不到安装的 OCR 引擎 Tesseract 或者 Tesseract 没有在你的环境变量 PATH 中。为了解决这个问题,你需要安装 Tesseract 并将其添加到 PATH 中。你可以从以下链接下载 Tesseract:https://github.com/UB-Mannheim/tesseract/wiki。安装完成后,将 Tesseract 的安装路径添加到 PATH 中即可。
相关问题
上面的代码运行后出现了报错信息Traceback (most recent call last): File "E:/PyCharm/test/rename/PDFpick.py", line 29, in <module> text = pytesseract.image_to_string(img_gray, lang=ocr_language, config='--psm 4') File "E:\python3.8.8\lib\site-packages\pytesseract\pytesseract.py", line 486, in image_to_string return { File "E:\python3.8.8\lib\site-packages\pytesseract\pytesseract.py", line 489, in <lambda> Output.STRING: lambda: run_and_get_output(*args), File "E:\python3.8.8\lib\site-packages\pytesseract\pytesseract.py", line 352, in run_and_get_output run_tesseract(**kwargs) File "E:\python3.8.8\lib\site-packages\pytesseract\pytesseract.py", line 275, in run_tesseract proc = subprocess.Popen(cmd_args, **subprocess_args()) File "E:\python3.8.8\lib\subprocess.py", line 858, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "E:\python3.8.8\lib\subprocess.py", line 1311, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, PermissionError: [WinError 5] 拒绝访问。
<think>嗯,用户遇到了在Python中使用pytesseract时出现的PermissionError,具体是[WinError 5]拒绝访问的问题。我需要帮他分析可能的原因,并提供解决方案。首先,我应该回忆一下常见的权限问题可能出现在哪些环节。
首先,用户提到的是路径权限问题,可能涉及到pytesseract调用的Tesseract-OCR路径。记得之前有遇到过类似的问题,比如路径配置错误或者没有管理员权限。比如,在安装Tesseract时,默认路径可能需要管理员权限才能访问,或者用户可能将Tesseract安装在了受限制的目录,比如Program Files下,而Python脚本运行时没有足够的权限去访问那个路径。
另外,用户可能没有正确配置pytesseract的路径。在之前的引用中,用户提到过修改pytesseract.py文件中的tesseract_cmd路径。所以,可能需要检查这个配置是否正确,是否指向了正确的Tesseract安装位置。如果路径中有空格或者特殊字符,也可能导致问题,比如Program Files这样的目录,路径需要用双引号包裹。
然后,考虑权限问题。如果Tesseract的安装目录权限不足,可能需要修改目录权限,让用户有读取和执行的权限。或者,用户可能需要以管理员身份运行Python脚本,特别是在写入某些受保护目录时。
另外,临时文件的处理也可能导致权限问题。比如,pytesseract在运行过程中可能会生成临时文件,如果临时目录(如系统的Temp文件夹)权限不足,也可能引发错误。这时候需要检查环境变量中的临时目录,或者显式指定临时目录的位置。
还有可能的情况是防病毒软件或安全软件阻止了Python进程访问Tesseract,这时候需要暂时关闭这些软件进行测试。
总结下来,可能的解决方案步骤包括:1. 检查并正确配置pytesseract的tesseract_cmd路径;2. 以管理员身份运行Python脚本;3. 修改Tesseract安装目录的权限;4. 检查临时目录权限;5. 处理防病毒软件干扰;6. 重新安装到无空格路径。
在给出具体步骤时,需要详细说明如何修改路径,比如在代码中直接设置pytesseract.pytesseract.tesseract_cmd,或者修改pytesseract.py文件。同时,提醒用户注意路径中的空格问题,建议安装到简单路径如C:\Tesseract-OCR。
此外,生成的相关问题可以涉及其他常见的OCR错误,比如FileNotFoundError,路径配置问题,或者如何测试Tesseract是否正确安装等。</think>### pytesseract出现PermissionError的解决方案
当Python调用pytesseract时出现`PermissionError: [WinError 5] 拒绝访问`,通常与以下四个关键环节相关:
1. **Tesseract-OCR路径权限问题**
- 检查Tesseract安装路径(默认:`C:\Program Files\Tesseract-OCR`)
- 右键点击安装目录 > 属性 > 安全 > 添加当前用户并赋予完全控制权限
- 或直接将Tesseract安装到无空格路径如`C:\Tesseract-OCR`[^1]
2. **代码层配置方法**
```python
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Tesseract-OCR\tesseract.exe' # 注意路径转义
```
3. **临时文件处理**
- 检查系统临时文件夹(`%TEMP%`)的写入权限
- 可手动指定临时目录:
```python
pytesseract.pytesseract.temp_dir = r'D:\custom_temp'
```
4. **执行权限提升**
- 以管理员身份运行CMD/PowerShell
- 在IDE中右键选择"以管理员身份运行"
Traceback (most recent call last): File "D:\2212406121017fzh\main.py", line 6, in <module> html = requests.get(url,headers=header) File "D:\Anaconda3\lib\site-packages\requests\api.py", line 73, in get return request("get", url, params=params, **kwargs) File "D:\Anaconda3\lib\site-packages\requests\api.py", line 59, in request return session.request(method=method, url=url, **kwargs) File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 573, in request prep = self.prepare_request(req) File "D:\Anaconda3\lib\site-packages\requests\sessions.py", line 484, in prepare_request p.prepare( File "D:\Anaconda3\lib\site-packages\requests\models.py", line 369, in prepare self.prepare_headers(headers) File "D:\Anaconda3\lib\site-packages\requests\models.py", line 489, in prepare_headers for header in headers.items(): AttributeError: 'set' object has no attribute 'items' 进程已结束,退出代码1
根据您提供的信息,看起来是您在使用requests库时出现了错误。根据错误信息,代码中的headers应该是一个set对象,而不是一个dict对象,所以出现了'AttributeError: 'set' object has no attribute 'items''的错误。
您可以尝试将headers改为一个dict对象,例如:
```python
import requests
url = 'http://example.com/api'
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
print(response.text)
```
在这个例子中,我们使用了一个包含User-Agent头的headers字典。请确保headers是一个dict对象,并且您的请求URL有效。
阅读全文
相关推荐

















