Error occurs after packaging python code to exe

Hi Aspose Team, i use AsposeCells for generating Excel file with format xlsx from HTML file. Firstly, with my python code, it works well. But when i try to convert my script into exe file, i got this error. I didnt find down any solution for this. Please help me !!!
image.png (358.7 KB)

@silm,

Apparently it looks like configuration issue on your end where it may not find Aspose.Cells for Python library/jar. So, you should sort it out accordingly. We will also evaluate your issue soon.

Thanks. I dont know where can i refer to get the solution for this. I only install AsposeCells from PIP and dont make any setting in my PC. Please help me solve this issue, thank you

@silm
Please provide us more details: package tool, package script etc. We will investigate the issue.

i’m using VSCode for implementing my script. I use AsposeCells for converting from HTML to Excel with Jpype 1.2.1 . The version of AsposeCell is 22.10.0

@silm
How do you package the scripts to exe?

i’ve used PyInstaller or Auto-py-to-exe but got this error also.
image.png (19.2 KB)
I traced in api.py file and saw that com.aspose.cell wasnt imported, but i can run my script without error. Please help me. Thanks a lot

@silm
The issue should be caused by the below code in “__init__.py

__cells_jar_dir__ = os.path.dirname(__file__)

addClassPath(os.path.join(__cells_jar_dir__, "lib", "aspose-cells-22.10.jar"))

addClassPath(os.path.join(__cells_jar_dir__, "lib", "bcprov-jdk15on-160.jar"))

addClassPath(os.path.join(__cells_jar_dir__, "lib", "bcpkix-jdk15on-1.60.jar"))

addClassPath(os.path.join(__cells_jar_dir__, "lib", "JavaClassBridge.jar"))

The jars cannot be load by JPype correctly when packaging in exe. Please trace “__file__” and “__cells_jar_dir__”, and check if the jars exist in the path.

image.png (10.4 KB)
image.png (20.2 KB)

Hi this is my tracing in folder and code. It is available in this folder. This issue still come

@silm
Please check them in unpackged tmp folder when running the exe. Please trace the variable values of __file__ and __cells_jar_dir__ when running the exe.

image.png (52.5 KB)
I tried to debug with file and cells_jar_dir . The exe file was packeged so i dont know where can i get these information that you want.

How can i do it? Please help us or can you give me some way to contact by Teams or Skype to solve it faster?

I’m a new begginer in Python and Aspose also. Thank you

@silm
The exe generated by directly using pyinstaller example.py will indeed have the problems you mentioned. Assuming example.py is your application.
Below is my solution:

  1. run pyinstaller example.py, there will be an example.spec file generated.
  2. edit example.spec like below:
mydatas = [('./aspose-cells-22.11.jar', '.'),
				('./bcprov-jdk15on-160.jar', '.'),
				('./bcpkix-jdk15on-1.60.jar', '.'),
				('./JavaClassBridge.jar', '.') ]

a = Analysis(
    ['example.py'],
    pathex=[],
    binaries=[],
    datas=mydatas,
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
  1. copy the jars (in asposecells/lib folder where installed) to the same folder of example.py,
  2. add the following code to the beginning of example.py
import os

from jpype import *

__cells_jar_dir__ = os.path.dirname(__file__)

addClassPath(os.path.join(__cells_jar_dir__, "aspose-cells-22.11.jar"))

addClassPath(os.path.join(__cells_jar_dir__, "bcprov-jdk15on-160.jar"))

addClassPath(os.path.join(__cells_jar_dir__, "bcpkix-jdk15on-1.60.jar"))

addClassPath(os.path.join(__cells_jar_dir__, "JavaClassBridge.jar"))
  1. edit __init__.py (in asposecellsfolder where installed) of aspose as below:
from __future__ import absolute_import

__all__ = ['api']
  1. run pyinstaller example.spec
    Now your example.exe should work well.

Hi, firstly, i tried to do the same thing that you’ve already said. The importing error was removed. But i still cant run my exe. A quick command window come and disappear very fast and not thing happen.
image.png (77.1 KB)
This is error was appearred when i change spec file and try to run it by pyinstaller
These pic is my change.
image.png (67.3 KB)
image.png (8.9 KB)
image.png (14.7 KB)

Is there any thing wrong in my change ?
Thanks a lot Mr Liu

i also cant see what is the log say and what is the error :((

image.jpg (134.6 KB)
i think this error wasnt resolved :frowning:
image.png (109.4 KB)

@silm,

We are sorry that the suggested solution does not work on your end. We will look into it further and get back to you soon.

Thanks a lot for your support. Hoping the solution from you soon. It looks like the lib havent added into exe package. When i run into Atempping ‘datas’ into exe , notthing happen and it’s up. Thanks again Aspose Team.

@silm
Please change your jar name to aspose-cells-22.10.jar in below 2 places:
mydatas = [('./aspose-cells-22.10.jar', '.'),

addClassPath(os.path.join(__cells_jar_dir__, "aspose-cells-22.10.jar"))

Hi @Nick.Liu, i have already changed into 22.10. I will show you my folder.
image.png (40.9 KB)
image.png (27.0 KB)
image.png (17.6 KB)
My init.py and when i try to run Pyinstaller GUI.spec
image.png (122.3 KB)
Whenever i come to Appending ‘datas’ from .spec , it will stop.

Thanks for your support mr @Nick.Liu

and this issue still come, still failed to import com.aspose