skip to Main Content

I need to run a pip install command in an initcontainer. I´m using the python:3.9-slim-buster image.

I created the following code, however I get the following error:

/usr/local/bin/python3: No module named pip install moduleexample

Code:

        spec:
          volumes:
          - name: agent-volume
            emptyDir: {}
          initContainers:
          - name: dd-apm-init
            image: python:3.9-slim-buster
            command: ["python3", "-m", "pip install moduleexample"]
            resources: {}
            volumeMounts:
            - name: agent-volume
              mountPath: /usr/local/lib/python3.9/site-packages
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            imagePullPolicy: IfNotPresent

Any suggestions?

================================================================
UPDATE:

Pip Install works with image python:3.8-slim-buster.

It seems that for 3.9 pip is being installed in site-packages, while it is not included in default sys.path.

When I try to run it from site-packages. I get an Access is denied error.

2

Answers


  1. Try splitting the whole command:

     ["python3", "-m", "pip", "install", "moduleexample"]
    
    Login or Signup to reply.
  2. You have given the command in the wrong format. It should be something like this –

    spec:
          volumes:
          - name: agent-volume
            emptyDir: {}
          initContainers:
          - name: dd-apm-init
            image: python:3.9-slim-buster
            command: ["python3", "-m", "pip", "install", "moduleexample"]
            resources: {}
            volumeMounts:
            - name: agent-volume
              mountPath: /usr/local/lib/python3.9/site-packages
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            imagePullPolicy: IfNotPresent
    

    Hope this would resolve the issue for you!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search