简体   繁体   English

我可以通过 vscode 在带有虚拟环境的 python 文件夹下创建文件并“正常工作”吗?

[英]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).所以我最近了解到并且被告知在虚拟环境中工作,或者养成这样做的习惯,最适合 python(我假设对于许多其他适用的语言)。 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.因此,我可以通过 mac 控制台上的 virtualenv 创建一个虚拟环境,并让它激活和停用控制台中的所有恶作剧。 For example, when I work with this folder I have created a virtual environment for (via console) in vscode, it looks like this .例如,当我使用这个文件夹时,我在 vscode 中为(通过控制台)创建了一个虚拟环境,它看起来像这样 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.我确保它在屏幕截图左下角运行的 python 包括由“('learnpp')”符号指出的虚拟环境 python,因为我认为这是我想要的。 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?在我开始处理任何事情之前,我是否必须 go 激活/停用控制台上的虚拟环境,尽管它是这样设置的(如屏幕截图中所示),以便环境每次都能实际工作,还是 IDE 照顾它?

  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.在同一个屏幕截图中,除了“draft.py”文件之外的所有内容都是由于在所见文件夹中创建虚拟环境而预加载的,我强烈认为该文件夹管理/运行虚拟环境,所以我想知道是否可以“继续我的day”尽管存在所有提到的东西,但仍会创建文件和文件夹。 (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. (我想我会为我正在创建的应用程序创建一个单独的文件夹,以使虚拟环境文件夹中的生活更轻松,或者我最好从根文件夹创建一个全新的文件夹?)换句话说,而不是 LEARN。 PP/learnpp/"我的应用程序的文件夹" 我将分别从 LEARN.PP/ 创建一个新文件夹。

  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!最后,感谢您的宝贵时间,希望您有美好的一天!

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.对于 VS Code 中的虚拟环境,建议将其文件夹和脚本分开,避免文件干扰的影响,分开更便于管理。

在此处输入图像描述

For example: 1. ".env" and ".env_3.9" are two virtual environment folders, which have their own dependencies and installed modules and so on;例如: 1. 、“.env”和“.env_3.9”是两个虚拟环境文件夹,有各自的依赖和安装的模块等; 2. ".vscode" is the folder where the configuration files are stored ( settings.json ; launch.json ; tasks.json and so on.); 2. “.vscode”是存储配置文件的文件夹( settings.jsonlaunch.jsontasks.json等); 3. "a_De" is the folder where the python script is stored. 3. “a_De”是python脚本存放的文件夹。 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 .关于在VS Code中使用python的更多信息,可以参考:在Visual Studio Code中编辑Python和在VS Code和 集成终端中使用Python环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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