Skip to content
Advertisement

Can I just create files and “work as normal” under a python folder with a virtual environment on it via vscode?

I wasn’t sure exactly how to ask my question in one concise sentence for the title so please give me the chance to be a bit more specific here.

So I’ve recently learned and have been told that working in virtual environments, or getting in the habit of doing so, is best for python (and I assume for many other applicable languages). Thus, I can create a virtual environment via virtualenv on the mac console and get it to activate and deactivate all that shenanigans in console. For example, when I work with this folder I have created a virtual environment for (via console) in vscode, it looks like this. I made sure that the python it was running seen on the bottom left of the screenshot included the virtual environment python noted by the “(‘learnpp’)” symbol as I assume it’s what I want. Now, my question(s) are:

  1. do I have to go activate/deactivate the virtual environment on console before I start to work on anything despite having it set up like so (like in the screenshot) for the environment to actually work every time or does the IDE take care of it?

  2. in the same screenshot, everything except the “draft.py” file was preloaded as a result of creating the virtual environment in seen folder which I strongly assume manages/runs the virtual environment so I was wondering if it was ok to “go about my day” creating files and folders despite all the mentioned things present. (I imagine I would just create a separate folder for the application I am creating to make life easier within the virtual environment folder OR would I be better off making an entirely new folder from the root folder?) In other words, instead of LEARN.PP/learnpp/”folder for my application” I would just create a new folder from LEARN.PP/ separately.

  3. anything else useful I should know? (feel free to throw anything at me since I am a beginner)

Lastly, thanks for your time and I hope you have a great day!

Advertisement

Answer

For the virtual environment in VS Code, it is recommended that you separate its folders and scripts to avoid the impact of file interference, and separating them is easier to manage.

enter image description here

For example: 1. “.env” and “.env_3.9” are two virtual environment folders, which have their own dependencies and installed modules and so on; 2. “.vscode” is the folder where the configuration files are stored (settings.json; launch.json; tasks.json and so on.); 3. “a_De” is the folder where the python script is stored. and we can also store other types of files (executable files, read files and so on).

For more information about the use of python in VS Code, you can refer to: Editing Python in Visual Studio Code and Using Python environments in VS Code and Integrated Terminal.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement