简体   繁体   中英

Visual Code how can I activate the virtual environment automatically?

Maybe a simple question, but I cannot figure it out. I work within Visual Studio Code on a MacBook. Within a directory I create a virtual environment and have activated that with source .venv/bin/activate scripts and everything works fine. In the terminal I see (.venv) (base) gaston@MacBook-Pro WebScraping %

When I start visual code another time and open this same directory I do not see the (.venv) so I again give manually the command to activate.

My question is there a way to activate the virtual environment automatically when opening the directory?

VS Code Default Python Interpreter Path

You can do this in a number of ways. If your goal is to have the virtual environment selected immediately at the launch of VS Code, you will have to target that virtual environment as the Python Interpreter in VSC.

https://code.visualstudio.com/docs/python/environments

System Preferences->Settings->Python: Default Interpreter Path

You'll want to point it to your virtualenv Python installation, likely something like:

envFolder/bin/python3

VS Code Launch Configuration Python Interpreter

You can also set a specific launch configuration so that VSCode will still use your system Python instance by default; however, specific launch configurations will have the virtual environment specified.

https://code.visualstudio.com/docs/python/debugging

Thanks, I did something within settings and now it works. When I open VSC now it opens the directory and the right environment, just the way I wanted it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM