Aspose.PSD for Python via .NET : Process terminated. Couldn't find a valid ICU package installed on the system

Ubuntu 24.04
Python3.10.19
use temporary license

Code from doc

from io import BytesIO
from aspose.psd.fileformats.psd import PsdImage
from aspose.psd.fileformats.psd.layers import Layer
from aspose.psd import License

license = License()
licensePath = "Aspose.PSDforPythonvia.NET.lic"
license.set_license(licensePath)


inputFile = "output.png"
outputFile = "AddFileAsLayer.psd"

# Open file as Stream
with open(inputFile, "rb", buffering=0) as filestream:
    stream = BytesIO(filestream.read())
    stream.seek(0)

    # Create PSD Layer from Stream
    layer = Layer(stream)

    # Create PSD Image with the specified size
    psdImage = PsdImage(layer.width, layer.height)

    # Add Layer to PSD Image
    psdImage.layers = [layer]

    # Get Pixels from File
    pixels = layer.load_argb_32_pixels(layer.bounds)
    pixelsRange = range(len(pixels))

    # Fill the pixels data with some values
    for i in pixelsRange:
        if i % 5 == 0:
            pixels[i] = 500000

    # Fast Save of Updated Image Data
    layer.save_argb_32_pixels(layer.bounds, pixels)

    # Save PSD Image
    psdImage.save(outputFile)

Got Error

python main.py 
Process terminated. Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
   at System.Environment.FailFast(System.String)
   at System.Globalization.GlobalizationMode.GetGlobalizationInvariantMode()
   at System.Globalization.GlobalizationMode..cctor()
   at System.Globalization.CultureData.CreateCultureWithInvariantData()
   at System.Globalization.CultureData.get_Invariant()
   at System.Globalization.CultureInfo..cctor()
   at System.StringComparer..cctor()
   at System.StringComparer.get_OrdinalIgnoreCase()
   at System.Text.EncodingTable..cctor()
   at System.Text.EncodingTable.GetCodePageFromName(System.String)
   at System.Text.CodePagesEncodingProvider.GetEncoding(System.String)
   at System.Text.EncodingProvider.GetEncodingFromProvider(System.String)
   at System.Text.Encoding.GetEncoding(System.String)
   at Aspose.WrpGen.Interop.GenericMarshaler..cctor()
   at Aspose.WrpGen.Interop.GenericMarshaler.ToString(Aspose.WrpGen.Interop.PyStringArg*)
   at WrpNs_Aspose.WrpNs_PSD.WrpCs_License_7A7E8167.call_000_SetLicense(IntPtr, Aspose.WrpGen.Interop.PyStringArg*)
Aborted (core dumped)

@BaiLooong

Solution Overview

The crash is caused by the .NET runtime not being able to locate a valid ICU (International Components for Unicode) library on your Ubuntu 24.04 system.
Aspose.PSD for Python via .NET (which uses pythonnet to host the .NET runtime) needs ICU for all globalization‑related operations.

You have two reliable ways to fix the problem:

Option What it does When to use it
Install the ICU native package (recommended) Provides the required ICU libraries (libicu.so.*) that the .NET runtime can load. All normal scenarios – you get full globalization support.
Run .NET in invariant mode Disables globalization support so the runtime no longer looks for ICU. Only if you cannot install native packages (e.g., very restricted containers).

Below are step‑by‑step instructions for both approaches.


:one: Install ICU on Ubuntu 24.04

  1. Update the package index

    sudo apt-get update
    
  2. Install the ICU runtime (and optionally the development headers)

    sudo apt-get install -y libicu70   # Current version on Ubuntu 24.04
    # Optional – only needed if you compile native extensions yourself
    # sudo apt-get install -y libicu-dev
    
  3. Verify the library is available

    ldconfig -p | grep libicu
    

    You should see something like:

    libicuuc.so.70 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libicuuc.so.70
    libicui18n.so.70 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libicui18n.so.70
    libicudata.so.70 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libicudata.so.70
    
  4. Run your script again

    python3 main.py
    

    The process should now start without the “Couldn’t find a valid ICU package” error.


:two: Run .NET in Invariant (ICU‑free) Mode

If you cannot install native libraries (e.g., in a minimal Docker image), you can force the .NET runtime to operate in invariant mode. This disables all culture‑specific features, which is acceptable for most image‑processing tasks that do not rely on locale‑dependent formatting.

2.1 Using an environment variable

Add the following line before you start Python (or export it in your shell/profile):

export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1

Or start the script in a single command:

DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 python3 main.py

2.2 Using a runtimeconfig.json file

Create a file named Aspose.PSD.runtimeconfig.json in the same directory as your script (or in any folder that is reachable from the runtime) with the following content:

{
  "runtimeOptions": {
    "configProperties": {
      "System.Globalization.Invariant": true
    }
  }
}

When the .NET host (pythonnet) loads the Aspose.PSD assembly, it will pick up this setting and skip ICU loading.

Note: Running in invariant mode disables culture‑aware APIs (e.g., CultureInfo, number/date formatting). If your code does not use those APIs, this mode is safe.


:three: Minor Code Fixes (Optional but Recommended)

Your sample contains a couple of redundant calls:

license = License()
license.set_license(licensePath)   # Loads the file‑based license
license.set_license()             # Calls overload without arguments (temporary license)

If you want to test with a temporary (in‑memory) license, you can simply omit the file‑path call:

license = License()
license.set_license()   # Uses a temporary (free) license

Otherwise, keep only the file‑based call:

license = License()
license.set_license("Aspose.PSDforPythonvia.NET.lic")

Both variants work once the ICU issue is resolved.


:four: Verify Everything Works

Run the script again (with ICU installed or invariant mode enabled). You should see the PSD file AddFileAsLayer.psd created without the previous crash.

If you still encounter issues, please provide:

  • The exact .NET runtime version (dotnet --info)
  • The Python‑net version (python -c "import clr; print(clr.__version__)")
  • The full stack trace (if different)

Helpful Links


TL;DR

  1. Preferredsudo apt-get install libicu70 → run script again.
  2. Alternative – set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 (or use runtimeconfig.json).

Either approach will eliminate the “Couldn’t find a valid ICU package” fatal error and allow your PSD processing code to run successfully.

If you need further assistance, feel free to reply with the additional information requested above. Happy coding!

@BaiLooong could you please tell us if the message from ML bot helped you?
Also, there is solution to install ICU package via bash:

sudo apt-get install -y libicu70 and sudo apt-get install -y libicu-dev