RunpodR
Runpod3y ago
27 replies
Daan

Problem with venv

Hi,

This is my handler.py file:
#!/usr/bin/env python3
""" Example handler file. """

import runpod
import subprocess

# If your handler runs inference on a model, load the model here.
# You will want models to be loaded into memory before starting serverless.


def handler(job):
    
    return run_shell_script('./entrypoint.sh') 

def run_shell_script(script_path):
    try:
        result = subprocess.run([script_path], check=True, text=True, capture_output=True)
        return result.stdout
    except subprocess.CalledProcessError as e:
        return e.stderr


runpod.serverless.start({"handler": handler})


when entrypoint.sh has this code:
export TRANSFORMERS_CACHE=/workspace



rm -rf /workspace && ln -s /runpod-volume /workspace
  
source /workspace/.venv/bin/activate


cd workspace/.venv/bin

ls
it works fine and gives
{
  "delayTime": 3917,
  "executionTime": 1082,
  "id": "3d4277ce-31d8-442c-830b-8817be24ecae-e1",
  "output": "Activate.ps1\naccelerate\naccelerate-config\naccelerate-estimate-memory\naccelerate-launch\nactivate\nactivate.csh\nactivate.fish\nconvert-caffe2-to-onnx\nconvert-onnx-to-caffe2\ndistro\nf2py\nhttpx\nhuggingface-cli\nisympy\nnormalizer\nopenai\npip\npip3\npip3.11\npython\npython3\npython3.11\nspacy\ntorchrun\ntqdm\ntransformers-cli\nweasel\n",
  "status": "COMPLETED"
}
Solution
Finally works, thanks for all the help! The issue was the base image that was different.
Was this page helpful?