Reputation: 908
I am doing a course in which I make an application using fastapi. I started creating a virtual environment with fastapi and uvicorn, later what I did was continue the development using docker containers, one for the application and another for the database. There is a file called requirements.txt, and when the python image (based on python:3.10-slim-buster) is built all the dependencies are installed. However, in my visual studio code it does not recognize these dependencies since it selects my local version of python as interpreter. I don't know how this works, but is there any way that visual studio code uses the version of python that I have in the container with its dependencies as interpreter?
Upvotes: 1
Views: 4218
Reputation: 287
Alternatively, if all of your dependencies are installed inside the docker container instead of a local venv, you can do the following:
F1
) -> Dev Containers: Attach to Running Container...
> [docker container]
/opt/app
which python
to see where docker's python livesF1
) -> Python: Select Interpreter
-> paste the path from Step 6Tah dah!
Upvotes: 3
Reputation: 97
Inside VS Code, go into your python file, do ctrl + shift + p
(Windows)/shift + command + p
(Mac) to Python: select interpreter
.
Enter interpreter path
, go to the path of the virtual environment with your dependencies you created at the beginning and select the python executable.
Upvotes: 1