Cannot run executable because USER_SITE in paddle is None

378 Views Asked by At

I have a Flask app that runs OCR functionality using PaddleOCR. My goal now is to create executable file from it. I have tried PyInstaller and py2app but both of them ended up having the same error. At first the executable were created, but when I run it on terminal, I got an error and the app was terminated. The error is

File ".../dist/ocr-app.app/Contents/Resources/lib/python3.9/paddle/fluid/core.py", line 392, in set_paddle_lib_path
    lib_dir = os.path.sep.join([site.USER_SITE, 'paddle', 'libs'])
TypeError: sequence item 0: expected str instance, NoneType found

So there I got site.USER_SITE is None. Previously I have successfully created executables for different projects using py2app, but not using Paddle. I tried to tweak a bit of code in the executable file package from the previous project to print site.USER_SITE but the value was also None.

So basically, by default the value of site.USER_SITE is None in executables, but this time I need it not to be None. Is there any solution or workaround for this?

In case needed, I am using python3.9, py2app 0.28.4, Flask 2.2.2, paddlepaddle 2.3.2, paddleocr 2.6.0.1

Edit:

I have as well read the documentation of python site module, in it said site.USER_SITE can be None if getusersitepackages() hasn’t been called yet. But I don't know when and where it should be called, and I don't know what to do either with that information.

1

There are 1 best solutions below

0
On

replacing site.USER_SITE by site_dir in your "...app/.../core.py" will solve this error.