we’re evaluating moving from LibreOffice to Aspose.Words Python. Unfortunately, we’re running into problems right away. We’re using the official python:3.11 docker image.
Dockerfile
FROM python:3.11
WORKDIR /home
COPY some.docx ./
COPY program.py ./
RUN pip install aspose-words
CMD ["python", "program.py"]
program.py
import aspose.words as aw
aw.Document("some.docx").save("some.pdf")
Building the image and running it fails with the following error message:
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_Words.WrpCs_Document_44597C31.ctor_001_Document(Aspose.WrpGen.Interop.PyStringArg*)
Searching the internet, this error can be resolved adding
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
to the Dockerfile, but I don’t understand the consequences of this env variable. Running the modified image, the error changes to:
No usable version of libssl was found
And I have not found a way to install libssl1 on the python:3.11 image.
That means that Aspose.Words for Python is not usable via the official python docker image. Can anyone help with a workaround?
FROM python:3.11 AS base
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
RUN apt-get update && apt-get install -y libgdiplus
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
RUN dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
RUN pip install aspose-words
# Copy function code
COPY app.py ./
ENTRYPOINT ["python3", "app.py"]
thanks for the quick response @alexey.noskov , I’ll try that first thing in the morning. Can you say something about the consequences of setting ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 ?
So it seems libicu72 is installed. Is Aspose.Words maybe expecting a different version?
Also, I read the information about globalization invariant mode but I still don’t understand what exactly are the consequences. If I, for example, convert a docx to pdf or txt, will this work flawlessly for non-ascii text?
I’d rather have the library fully working before continuing my research.
EDIT: After fiddeling around some more I can already tell that saving a german word document to TXT fails with
RuntimeError: Proxy error(CultureNotFoundException): Culture is not supported. (Parameter 'culture')
1033 (0x0409) is an invalid culture identifier.
Could you please attach the document that causes the problem upon conversion and provide code you use for testing? I have tested with a dummy document and cannot reproduce the problem on my side.
The file in question is GESSI-Exit-Muster-SPA.docx which is a common legal document. Please note, that on my local machine (Ubuntu 22.04) it does work. It just doesn’t work in the docker container.
To execute the test, a valid license file Aspose.WordsforPythonvia.NET.lic is needed and has to be placed in the root directory of the repo.
@tjmaul Thank you for additional information. I managed to reproduce the problem on my side. It is a strange problem. It looks like .NET does not work with new version of ICU. I tried installing an older version and the code works. Here is an updated Dockerfile which works with your document:
FROM python:3.11 AS base
RUN apt-get update && apt-get install -y libgdiplus
# Install libssl1
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
RUN dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
# install an older version of ICU
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu70_70.1-2_amd64.deb
RUN dpkg -i libicu70_70.1-2_amd64.deb
RUN pip install aspose-words
# Copy function code
COPY app.py ./
ENTRYPOINT ["python3", "app.py"]
Could you please try on your side and let us know if it works on your side.
hey @alexey.noskov,
I just tried and it works. It also explains why it works on my local Ubuntu desktop install, because the installed version there is libicu70.
Please note that I’m not interested in running the latest libicu. I just want it to work in general and not be dragged into this rabbit hole
thank you @alexey.noskov for your help! I guess for now this workaround is good enough and I assume with newer versions of both dotnet and Aspose.Words, this problem will resolve itself. It might be worth communicating this problems to the developers, though.
@tjmaul It is perfect that the workaround works for you. Please feel free to ask in case of any other issues.
I also logged an issue with the above analysis provided and we will further investigate whether we can improve this somehow.
1 Like
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.