代码之家  ›  专栏  ›  技术社区  ›  maygon

ironpdf RuntimeError:未能创建。NET运行时

  •  0
  • maygon  · 技术社区  · 2 年前

    我正在使用ironpdf遵循pdf阅读器教程 this link

    但我得到了这个错误:

    ---------------------------------------------------------------------------
    RuntimeError                              Traceback (most recent call last)
    File ~\anaconda3\lib\site-packages\pythonnet\__init__.py:77, in _create_runtime_from_spec(spec, params)
        76 elif spec == "coreclr":
    ---> 77     return clr_loader.get_coreclr(**params)
        78 else:
    
    File ~\anaconda3\lib\site-packages\clr_loader\__init__.py:121, in get_coreclr(runtime_config, dotnet_root, properties, runtime_spec)
        120 if dotnet_root is None:
    --> 121     dotnet_root = find_dotnet_root()
        123 temp_dir = None
    
    File ~\anaconda3\lib\site-packages\clr_loader\util\find.py:57, in find_dotnet_root()
        56 if not dotnet_cli:
    ---> 57     raise RuntimeError("Can not determine dotnet root")
        59 return dotnet_cli.resolve().parent
    
    RuntimeError: Can not determine dotnet root
    
    The above exception was the direct cause of the following exception:
    
    RuntimeError                              Traceback (most recent call last)
    Cell In[10], line 1
    ----> 1 from ironpdf import *
        3 # Load existing PDF document
        4 pdf = PdfDocument.FromFile("ActaConstitutiva0.pdf")
    
    File ~\anaconda3\lib\site-packages\ironpdf\__init__.py:8
        6 # load .NET core
        7 from pythonnet import load
    ----> 8 load("coreclr")
        9 # imports
        10 import clr
    
    File ~\anaconda3\lib\site-packages\pythonnet\__init__.py:133, in load(runtime, **params)
        131         set_runtime_from_env()
        132     else:
    --> 133         set_runtime(runtime, **params)
        135 if _RUNTIME is None:
        136     raise RuntimeError("No valid runtime selected")
    
    File ~\anaconda3\lib\site-packages\pythonnet\__init__.py:29, in set_runtime(runtime, **params)
        26     raise RuntimeError(f"The runtime {_RUNTIME} has already been loaded")
        28 if isinstance(runtime, str):
    ---> 29     runtime = _create_runtime_from_spec(runtime, params)
        31 _RUNTIME = runtime
    
    File ~\anaconda3\lib\site-packages\pythonnet\__init__.py:90, in _create_runtime_from_spec(spec, params)
        82     raise RuntimeError(
        83         f"""Failed to create a default .NET runtime, which would
        84             have been "{spec}" on this system. Either install a
    (...)
        87             (see set_runtime_from_env)."""
        88     ) from exc
        89 else:
    ---> 90     raise RuntimeError(
        91         f"""Failed to create a .NET runtime ({spec}) using the
        92         parameters {params}."""
        93     ) from exc
    
    RuntimeError: Failed to create a .NET runtime (coreclr) using the
                    parameters {}.
    

    我试着卸载ironpdf,但没有成功。。。

    我正在使用 jupyter笔记本6.4.12 , python 3.10.6 ironpdf-2023.7.9 版本

    成功地 已安装ironpdf pip

    有什么办法解决这个问题吗?

    这是我的代码:

    from ironpdf import *
    
    # Load existing PDF document
    pdf = PdfDocument.FromFile("mypdf.pdf")
    
    # Extract text and images from PDF document
    all_text = pdf.ExtractAllText()
    all_images = pdf.ExtractAllImages()
    
    # Or, extract text and images from specific pages
    page_2_text = pdf.ExtractTextFromPage(1)
    for index in range(pdf.PageCount):
        page_number = index + 1
        images = pdf.ExtractBitmapsFromPage(index)
    

    任何帮助都将不胜感激

    0 回复  |  直到 2 年前
        1
  •  0
  •   djrecipe    2 年前

    IronPdf for Python是一个围绕Iron Pdf的包装器。NET库,因此需要。NET 6.0。

    你可以下载。NET 6从这里开始: https://dotnet.microsoft.com/en-us/download/dotnet/6.0

    正在查看 setup.py 对于IronPdf,他们试图运行。NET安装脚本时,将IronPdf导入Python脚本;但是,这并不总是成功的,因为您的Python脚本可能没有可执行权限。