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 :)
CodePudding user response:
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
CodePudding user response:
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