Error: Failed to Locate IronPDF in Python

This article was translated from English: Does it need improvement?
Translated
View the article in English

假设您已安装 .NET 6.0 SDK,并通过使用以下命令通过 pip 安装了 IronPdf:

 pip install ironpdf

执行 Python 脚本时,您可能会遇到以下异常:

Exception has occurred: Exception
Failed to locate IronPdf.Slim.dll at 'C:\Users\Name\AppData\Local\Programs\Python\Python311/IronPdf.Slim'. Please see /troubleshooting/quick-ironpdf-troubleshooting/ for more information
  File "C:\Users\Name\OneDrive\Documents\IronPdfPythonNew\working\viewport.py", line 1, in <module>
    from ironpdf import *
Exception: Failed to locate IronPdf.Slim.dll at 'C:\Users\Name\AppData\Local\Programs\Python\Python311/IronPdf.Slim'. Please see https://ironpdf.com/troubleshooting/quick-ironpdf-troubleshooting/ for more information

解决方案

可以如下指定包含 IronPdf.Slim 的目录:

import sys
# Set the path to include the directory containing the IronPdf.Slim files.
# Users can determine this location by running `pip uninstall ironpdf` and pressing `N` to view the installation path.
sys.path.append('/path/to/python/packages')
import sys
# Set the path to include the directory containing the IronPdf.Slim files.
# Users can determine this location by running `pip uninstall ironpdf` and pressing `N` to view the installation path.
sys.path.append('/path/to/python/packages')
PYTHON

例如

import sys
# Add the directory of the IronPdf installation to the path for module resolution.
# This should point to the root directory of where IronPdf is installed.
sys.path.append(r'C:\Users\lyty1\AppData\Local\Programs\Python\Python311\Lib\site-packages')

from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Create a PDF from a URL or local file path
pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")

# Export to a file or Stream
pdf.SaveAs("url.pdf")
import sys
# Add the directory of the IronPdf installation to the path for module resolution.
# This should point to the root directory of where IronPdf is installed.
sys.path.append(r'C:\Users\lyty1\AppData\Local\Programs\Python\Python311\Lib\site-packages')

from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Create a PDF from a URL or local file path
pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")

# Export to a file or Stream
pdf.SaveAs("url.pdf")
PYTHON

原因

大多数第三方库安装在名为“site-packages”的目录中,该目录位于 Python 安装目录中,或如果您使用虚拟环境,则位于虚拟环境目录中。 这是 Python 解释器可访问的目录。

IronPDF 将安装 IronPdf.SlimIronPdf.Native.Chrome.Windows

具体位置可能会因操作系统和 Python 配置而异。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
版本: 2025.9 刚刚发布