Streamlit and paddleocr 3.0.0

Deploying a python program. https://crazyaisudokusolverultraedition.streamlit.app/
you can look up code and specific dependencies on github, but the problematic should be paddleocr 3.0.0

The error ocures when trying to import paddleocr(when you upload image). I think it’s because it wants to access some folders, which it shouldn’t? Mainly I want to know, if I can fix it.

────────────────────── Traceback (most recent call last) ───────────────────────
  /home/adminuser/venv/lib/python3.12/site-packages/streamlit/runtime/scriptru  
  nner/exec_code.py:121 in exec_func_with_error_handling                        
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/streamlit/runtime/scriptru  
  nner/script_runner.py:645 in code_to_exec                                     
                                                                                
  /mount/src/sudoku/semestral/app/gui/display.py:52 in <module>                 
                                                                                
    49                                                                          
    50                                                                          
    51 if __name__ == "__main__":                                               
  ❱ 52 │   display()                                                            
    53                                                                          
                                                                                
  /mount/src/sudoku/semestral/app/gui/display.py:26 in display                  
                                                                                
    23 │   │   with open(temp_image_path, "wb+") as f:                          
    24 │   │   │   f.write(uploaded_file.getbuffer())                           
    25 │   │   # Process the image to extract the Sudoku grid                   
  ❱ 26 │   │   sudoku_board = sscan.scan_table(temp_image_path)                 
    27 │   │   # Optionally, remove the temporary file after processing         
    28 │   else:                                                                
    29 │   │   # Example empty Sudoku board                                     
                                                                                
  /mount/src/sudoku/semestral/app/src/sudscan.py:33 in scan_table               
                                                                                
    30 │   │   - Detected text outside the 9x9 grid boundaries is ignored       
    31 │   """                                                                  
    32 │                                                                        
  ❱ 33 │   import paddleocr                                                     
    34 │   ocr = paddleocr.PaddleOCR(use_textline_orientation=False, lang='en'  
    35 │   │   │   │   │   text_detection_model_dir="app/official_models/PP-OC  
    36 │   │   │   │   │   text_recognition_model_dir="app/official_models/PP-  
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddleocr/__init__.py:15    
  in <module>                                                                   
                                                                                
    12 # See the License for the specific language governing permissions and    
    13 # limitations under the License.                                         
    14                                                                          
  ❱ 15 from ._models import (                                                   
    16 │   DocImgOrientationClassification,                                     
    17 │   DocVLM,                                                              
    18 │   FormulaRecognition,                                                  
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddleocr/_models/__init__  
  .py:15 in <module>                                                            
                                                                                
    12 # See the License for the specific language governing permissions and    
    13 # limitations under the License.                                         
    14                                                                          
  ❱ 15 from .doc_img_orientation_classification import DocImgOrientationClassi  
    16 from .doc_vlm import DocVLM                                              
    17 from .formula_recognition import FormulaRecognition                      
    18 from .layout_detection import LayoutDetection                            
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddleocr/_models/doc_img_  
  orientation_classification.py:15 in <module>                                  
                                                                                
    12 # See the License for the specific language governing permissions and    
    13 # limitations under the License.                                         
    14                                                                          
  ❱ 15 from ._image_classification import (                                     
    16 │   ImageClassification,                                                 
    17 │   ImageClassificationSubcommandExecutor,                               
    18 )                                                                        
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddleocr/_models/_image_c  
  lassification.py:22 in <module>                                               
                                                                                
    19 │   get_subcommand_args,                                                 
    20 │   perform_simple_inference,                                            
    21 )                                                                        
  ❱ 22 from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecut  
    23                                                                          
    24                                                                          
    25 class ImageClassification(PaddleXPredictorWrapper):                      
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddleocr/_models/base.py:  
  17 in <module>                                                                
                                                                                
     14                                                                         
     15 import abc                                                              
     16                                                                         
  ❱  17 from paddlex import create_predictor                                    
     18                                                                         
     19 from .._abstract import CLISubcommandExecutor                           
     20 from .._common_args import (                                            
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/__init__.py:25 in   
  <module>                                                                      
                                                                                
    22 │   │   _loaded_special_mods.append(mod)                                 
    23                                                                          
    24 from . import version                                                    
  ❱ 25 from .inference import create_pipeline, create_predictor                 
    26 from .model import create_model                                          
    27 from .modules import build_dataset_checker, build_evaluator, build_trai  
    28                                                                          
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/inference/__init__  
  .py:16 in <module>                                                            
                                                                                
    13 # limitations under the License.                                         
    14                                                                          
    15 from ..utils import logging                                              
  ❱ 16 from .models import create_predictor                                     
    17 from .pipelines import create_pipeline, load_pipeline_config             
    18 from .utils.hpi import HPIConfig                                         
    19 from .utils.pp_option import PaddlePredictorOption                       
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/inference/models/_  
  _init__.py:26 in <module>                                                     
                                                                                
    23                                                                          
    24 # from .table_recognition import TablePredictor                          
    25 # from .general_recognition import ShiTuRecPredictor                     
  ❱ 26 from .anomaly_detection import UadPredictor                              
    27 from .base import BasePredictor                                          
    28 from .doc_vlm import DocVLMPredictor                                     
    29 from .face_feature import FaceFeaturePredictor                           
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/inference/models/a  
  nomaly_detection/__init__.py:15 in <module>                                   
                                                                                
    12 # See the License for the specific language governing permissions and    
    13 # limitations under the License.                                         
    14                                                                          
  ❱ 15 from .predictor import UadPredictor                                      
    16                                                                          
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/inference/models/a  
  nomaly_detection/predictor.py:19 in <module>                                  
                                                                                
     16                                                                         
     17 import numpy as np                                                      
     18                                                                         
  ❱  19 from ....modules.anomaly_detection.model_list import MODELS             
     20 from ....utils.func_register import FuncRegister                        
     21 from ...common.batch_sampler import ImageBatchSampler                   
     22 from ...common.reader import ReadImage                                  
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/modules/__init__.p  
  y:18 in <module>                                                              
                                                                                
     15                                                                         
     16 from .anomaly_detection import UadDatasetChecker, UadEvaluator, UadExp  
     17 from .base import build_dataset_checker, build_evaluator, build_export  
  ❱  18 from .face_recognition import (                                         
     19 │   FaceRecDatasetChecker,                                              
     20 │   FaceRecEvaluator,                                                   
     21 │   FaceRecExportor,                                                    
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/modules/face_recog  
  nition/__init__.py:15 in <module>                                             
                                                                                
    12 # See the License for the specific language governing permissions and    
    13 # limitations under the License.                                         
    14                                                                          
  ❱ 15 from .dataset_checker import FaceRecDatasetChecker                       
    16 from .evaluator import FaceRecEvaluator                                  
    17 from .exportor import FaceRecExportor                                    
    18 from .trainer import FaceRecTrainer                                      
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/modules/face_recog  
  nition/dataset_checker/__init__.py:20 in <module>                             
                                                                                
    17                                                                          
    18 from ...base import BaseDatasetChecker                                   
    19 from ..model_list import MODELS                                          
  ❱ 20 from .dataset_src import check_train, check_val                          
    21                                                                          
    22                                                                          
    23 class FaceRecDatasetChecker(BaseDatasetChecker):                         
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/modules/face_recog  
  nition/dataset_checker/dataset_src/__init__.py:16 in <module>                 
                                                                                
    13 # limitations under the License.                                         
    14                                                                          
    15                                                                          
  ❱ 16 from .check_dataset import check_train, check_val                        
    17                                                                          
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/modules/face_recog  
  nition/dataset_checker/dataset_src/check_dataset.py:22 in <module>            
                                                                                
     19 from PIL import Image, ImageOps                                         
     20                                                                         
     21 from .....utils.errors import CheckFailedError, DatasetFileNotFoundErr  
  ❱  22 from .utils.visualizer import draw_label                                
     23                                                                         
     24                                                                         
     25 def check_train(dataset_dir, output, sample_num=10):                    
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/modules/face_recog  
  nition/dataset_checker/dataset_src/utils/visualizer.py:19 in <module>         
                                                                                
     16 import PIL                                                              
     17 from PIL import ImageDraw, ImageFont                                    
     18                                                                         
  ❱  19 from ......utils.fonts import PINGFANG_FONT_FILE_PATH                   
     20                                                                         
     21                                                                         
     22 def colormap(rgb=False):                                                
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/utils/fonts/__init  
  __.py:96 in <module>                                                          
                                                                                
    93 │   PINGFANG_FONT_FILE_PATH = LOCAL_FONT_FILE_PATH                       
    94 │   SIMFANG_FONT_FILE_PATH = LOCAL_FONT_FILE_PATH                        
    95 else:                                                                    
  ❱ 96 │   PINGFANG_FONT_FILE_PATH = get_font_file_path("PingFang-SC-Regular.t  
    97 │   SIMFANG_FONT_FILE_PATH = get_font_file_path("simfang.ttf")           
    98                                                                          
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/utils/fonts/__init  
  __.py:34 in get_font_file_path                                                
                                                                                
    31 │   """                                                                  
    32 │   font_path = (Path(__file__).parent / file_name).resolve().as_posix(  
    33 │   if not Path(font_path).is_file():                                    
  ❱ 34 │   │   download(                                                        
    35 │   │   │   url=f"https://paddle-model-ecology.bj.bcebos.com/paddlex/Pa  
    36 │   │   │   save_path=font_path,                                         
    37 │   │   )                                                                
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/utils/download.py:  
  140 in download                                                               
                                                                                
    137 │   if overwrite:                                                       
    138 │   │   _remove_if_exists(save_path)                                    
    139 │   if not os.path.exists(save_path):                                   
  ❱ 140 │   │   _download(url, save_path, print_progress=print_progress)        
    141                                                                         
    142                                                                         
    143 def extract(file_path, extd_dir, print_progress=True):                  
                                                                                
  /home/adminuser/venv/lib/python3.12/site-packages/paddlex/utils/download.py:  
  60 in _download                                                               
                                                                                
     57 │   │   │   with open(save_path, "wb") as f:                            
     58 │   │   │   │   shutil.copyfileobj(r.raw, f)                            
     59 │   │   else:                                                           
  ❱  60 │   │   │   with open(save_path, "wb") as f:                            
     61 │   │   │   │   dl = 0                                                  
     62 │   │   │   │   total_length = int(total_length)                        
     63 │   │   │   │   if print_progress:                                      
────────────────────────────────────────────────────────────────────────────────
PermissionError: [Errno 13] Permission denied: 
'/home/adminuser/venv/lib/python3.12/site-packages/paddlex/utils/fonts/PingFang-
SC-Regular.ttf'

PaddleX seems to incorrectly assume that it can write to the directory where it is installed. I think it can only to be fixed in paddlex itself. You may want to bring this up with the paddlex devs.