-1

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!

  • There are multiple questions here, with 2 being a bit unclear and 3 being open-ended and off-topic. But as for 1., once you select an virtual env, VS Code saves that in the workspace settings ([reference](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment)). So all you have to do is set the virtual env, save that as a workspace, then every time you open that workspace, VS Code will reload that same virtual env. – Gino Mempin Mar 02 '21 at 01:35
  • "*anything else useful I should know*": Maybe read VS Code docs on [Getting Started with Python in VS Code](https://code.visualstudio.com/docs/python/python-tutorial). – Gino Mempin Mar 02 '21 at 01:39
  • @GinoMempin Thanks for the link and feedback for #1, I think i got the jist of it now. As for #2, in my attempt to rephrase the best I can, after using virtualenv for a desired folder, i create a folder inside that folder (in my case LEARN.PP/ is the root folder and /learnpp/ is the folder which has all the virtualenv stuff in it). Now with that being said, once I start creating whatever (an application/program/script/etc.) do I/should I create a separate folder from the root folder of LEAR.PP that will house all my files and packages or should I create a folder within LEARN.PP/learnpp/(so her – villagedumdum Mar 02 '21 at 06:25

1 Answers1

0

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.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25