Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Python libraries in the Visual Studio Code container

I can edit python code in a folder located in a Docker Volume. I use Visual Studio Code and in general lines it works fine.

The only problem that I have is that the libraries (such as pandas and numpy) are not installed in the container that Visual Studio creates to mount the volume, so I get warning errors.

How to install these libraries in Visual Studio Code container?

** UPDATE **

This is my application Dockerfile, see that the libraries are included in the image, not the volume:

FROM daskdev/dask

RUN /opt/conda/bin/conda create -p /pyenv -y
RUN /opt/conda/bin/conda install -p /pyenv scikit-learn flask waitress gunicorn \
    pytest apscheduler matplotlib pyodbc -y
RUN /opt/conda/bin/conda install -p /pyenv -c conda-forge dask-ml pyarrow -y
RUN /opt/conda/bin/conda install -p /pyenv pip -y
RUN /pyenv/bin/pip install pydrill 

And the application is started with docker compose:

version: '3'

services:   

  web:
    image: img-python
    container_name: cont_flask
    volumes:
      - vol_py_code:/code
    ports:
      - "5000:5000"
    working_dir: /code
    entrypoint:
      - /pyenv/bin/gunicorn
    command:
      - -b 0.0.0.0:5000
      - --reload
      - app.frontend.app:app
like image 895
ps0604 Avatar asked Aug 15 '26 02:08

ps0604


1 Answers

https://code.visualstudio.com/docs/python/python-tutorial
In the VScode documentation, there is a section called "Install and use packages" under the python tutorial. I think that will explain it to you.
Edit:
Have you added it to your dockerfile? Like:
RUN pip install pandas
Try to look at the answer to this question and see if it helps:
How to add Python libraries to Docker image
Edit2:
It seems like VSC are using the local environment, when it creates a container, and there isn't a devcontainer.json file.
I think you need to either install the libraries in your local environment or set up a development container in VSC:
https://code.visualstudio.com/docs/remote/create-dev-container
Microsoft have a GitHub repo with development container templates:
https://github.com/microsoft/vscode-dev-containers
If you already have set up a development container, can you please add your devcontainer.json file to your question, so it is possible to look at it?

like image 83
OleGregersen Avatar answered Aug 17 '26 15:08

OleGregersen