無法找到 IronPdf.Slim.dll

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

假設您已經使用以下命令通過 pip 安裝了 .NET 6.0 SDK 和 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 https://ironpdf.com/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
# This line should point to the root directory that contains the IronPdf.Slim folder.
# Users can determine this location by running `pip uninstall ironpdf` and pressing `N`.
sys.prefix = '/path/to/python/packages'
PYTHON

例如

import sys
# This line should point to the root directory that contains the IronPdf.Slim folder.
# Users can determine this location by running `pip uninstall ironpdf` and pressing `N`.
sys.prefix = r'C:\Users\lyty1\AppData\Local\Programs\Python\Python311'

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 配置而有所不同。