{"record":{"id":"cdc1219f6d60e468","repo":"PaddlePaddle/PaddleOCR","slug":"environment-variable-cuda-visible-devices-is-not-s-cdc121","errorCode":null,"errorMessage":"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id.","messagePattern":"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly\\. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"deploy/hubserving/structure_system/module.py","lineNumber":64,"sourceCode":"    type=\"cv/structure_system\",\n)\nclass StructureSystem(hub.Module):\n    def _initialize(self, use_gpu=False, enable_mkldnn=False):\n        \"\"\"\n        initialize with the necessary elements\n        \"\"\"\n        cfg = self.merge_configs()\n\n        cfg.use_gpu = use_gpu\n        if use_gpu:\n            try:\n                _places = os.environ[\"CUDA_VISIBLE_DEVICES\"]\n                int(_places[0])\n                print(\"use gpu: \", use_gpu)\n                print(\"CUDA_VISIBLE_DEVICES: \", _places)\n                cfg.gpu_mem = 8000\n            except:\n                raise RuntimeError(\n                    \"Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. If you wanna use gpu, please set CUDA_VISIBLE_DEVICES via export CUDA_VISIBLE_DEVICES=cuda_device_id.\"\n                )\n        cfg.ir_optim = True\n        cfg.enable_mkldnn = enable_mkldnn\n\n        self.table_sys = PPStructureSystem(cfg)\n\n    def merge_configs(self):\n        # default cfg\n        backup_argv = copy.deepcopy(sys.argv)\n        sys.argv = sys.argv[:1]\n        cfg = parse_args()\n\n        update_cfg_map = vars(read_params())\n\n        for key in update_cfg_map:\n            cfg.__setattr__(key, update_cfg_map[key])\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/hubserving/structure_system/module.py#L46-L82","documentation":"Raised during __init__ of the structure_system (PP-Structure end-to-end) hubserving module when use_gpu=True and the CUDA_VISIBLE_DEVICES check fails. The check (read env var, int() the first char) sits in a bare try/except, so unset/empty/non-digit values all raise this RuntimeError.","triggerScenarios":"Constructing the structure system module with use_gpu=True while CUDA_VISIBLE_DEVICES is missing or malformed.","commonSituations":"PP-Structure serving on GPU hardware where the device visibility env var was never exported; containers missing the -e CUDA_VISIBLE_DEVICES flag.","solutions":["export CUDA_VISIBLE_DEVICES=0 and then initialize with use_gpu=True.","Initialize with use_gpu=False for CPU deployments.","Verify the variable in the same shell/process that launches the service."],"exampleFix":"# before\nmod = StructModule(use_gpu=True)  # env unset -> RuntimeError\n\n# after\nimport os\nos.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\nmod = StructModule(use_gpu=True)\n# or\nmod = StructModule(use_gpu=False)","handlingStrategy":"validation","validationCode":"import os\n\nv = os.environ.get(\"CUDA_VISIBLE_DEVICES\")\nif USE_GPU and (not v or not v[0].isdigit()):\n    raise SystemExit(\"GPU requested but CUDA_VISIBLE_DEVICES invalid; export CUDA_VISIBLE_DEVICES=0\")\nmod = StructModule(use_gpu=USE_GPU)","typeGuard":null,"tryCatchPattern":"try:\n    mod = StructModule(use_gpu=True)\nexcept RuntimeError as e:\n    if \"CUDA_VISIBLE_DEVICES\" in str(e):\n        mod = StructModule(use_gpu=False)\n    else:\n        raise","preventionTips":["Make GPU env part of the deployment checklist for PP-Structure services.","Fail fast at startup with a clear message instead of crashing at module init.","Pin the env var in container specs so it is never shell-dependent."],"tags":["paddleocr","ppstructure","hubserving","gpu","cuda","environment"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}