skip to Main Content

Good day. I was using virtual environment in development stage (for python projects, of course). But one day, I decided to do everything using best practices, and followed one course. In that course, tutor uses docker-compose for all operations, and installs all dependencies to inside docker container. But I’m using vs code, and since no virtual environment is created, vs code does not recognize imports, because it looks at the main interpreter, in which I don’t have those dependencies. One way is to install all dependencies to the main interpreter, and I think it is not recommended. Another way, I think, is to create a virtual env for just containing the dependencies for vs code to refer it. But I’m not sure it is best practice or not. What is the best way of developing a python project using docker, and vs code ?

Fun fact: In tutors Vs code, there is no problem 🙂

3

Answers


  1. The first thing to understand is that the interpreter of the virtual environment is isolated from the real environment, so there is no need to call the dependencies in the virtual environment while using the main interpreter.

    I think the best way is to unify all operations in the virtual environment, so that the environment will not be disordered.

    You can also refer to this document for more information about vscode and docker

    Login or Signup to reply.
  2. morning,here is an example,https://github.com/miguelgrinberg/flasky
    you can learn from this project struct.
    in a word.you can use virtualenv in your develop env,when you commit your code,you may ingore venv dir,when you deploy your project ,you may use docker-compose to deploy.
    feel free

    Login or Signup to reply.
  3. Morning,
    I was having the same issue and the way I fixed it is:

    1. install the dependencies on the main computer
    2. press ctrl + shift + p and select python: select interpreter

    Then select the global python environment

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