pythonpdfruntime-errorpdf-readerironpdf

ironpdf RuntimeError: Failed to create a .NET runtime


i am following a pdf reader tutorial with ironpdf from this link

but i got this error:

---------------------------------------------------------------------------
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 {}.

i tried uninstalling ironpdf but it didnt worked tho...

i am using jupyter notebook 6.4.12, python 3.10.6 and ironpdf-2023.7.9 version

i succesfully installed ironpdf with pip

is there any way to solve this problem?

this is my code:

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)

any help would be appreciated 😀


Solution

  • IronPdf for Python is a wrapper around the IronPdf .NET library and thus requires .NET 6.0 to be installed.

    You can download .NET 6 from here: https://dotnet.microsoft.com/en-us/download/dotnet/6.0

    Looking at the setup.py for IronPdf, they try to run the .NET installation script when you import IronPdf into your Python script; however, this will not always succeed since your Python script may not have executable permissions.