I'm trying to make Python linters to work in VS Code when Python and all packages are installed in a Docker container.
I didn't use linters before. But as far as I understand how linters work (at least in VS Code), I need to point VS Code to Python interpreter and set paths to packages if needed. And this becomes a problem if everything is installed in Docker container.
I'm trying to use only Docker features. What I came up with is the following:
I tried to implement everything using Django sample project from Docker docs, so my files looks like following
docker-compose.yml
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
- ./.vscode/python:/usr/local/lib/python3.7 # The problem is here
ports:
- "8000:8000"
depends_on:
- db
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
requirements.txt
Django
psycopg2
Django project works when the line - ./.vscode/python:/usr/local/lib/python3.7
is commented.
But when I am trying to bind mount Python folder the same way as /code
folder mounted, I not only don't have content of this folder accessible locally, but Django project stops working.
Is it possible to mount Python executable in this way? Or maybe there is a better way to use arbitrary Python linters while using VS Code and Docker? It would be great to avoid:
Not the Docker side, just some VS code considerations
VS Code relies on two mechanisms for resolving python highlighing: environment and linter.
For environment you can check https://code.visualstudio.com/docs/python/environments, which basically says either python is availsble on the system in path, or pick virtual environmrnt you create, or provide a path to python executable in json.
https://code.visualstudio.com/docs/python/linting tells to install linter with pip, runnable from environment you configured or provide a path to linter in json.
So it looks the only things you need to replicate VSCode python linting is python executabe, installation of pylint and json configuration for vscode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With