且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python - 为 django 项目重新激活我的 virtualenv

更新时间:2023-09-16 14:50:22

Visual Studio 代码实际上有一种方便的方式来跟踪虚拟环境.在蓝色页脚栏的最底部,点击刷新图标旁边的,您应该会看到它是否可用.

Visual studio code actually has a convenient way of keeping track of virtual environments. At the very bottom in the blue footer bar, click next to the refresh icon, and you should see whether it's available.

如果它真的消失了,请不要担心.虚拟环境是完全可以消耗的——它会出现.现在,只需创建另一个,并确保这次在项目的根目录中创建它.

If it's really gone, don't sweat it. Virtual environments are completely expendable – it'll turn up. For now, just make another, and be sure you create it in your project's root directory this time.

您实际上通常不需要使用 vscode 激活 venv.只需 cd 进入项目根目录并使用 code . 打开 vscode.激活的环境将出现在页脚的同一位置.

You actually usually don't need to activate a venv with vscode. Just cd into the project root directory and open vscode with code .. The activated envionment will appear in that same spot in the footer.

另外,考虑使用 requirements.txt 文件,如果你一直把 virtualenv 放错地方,它会节省很多时间.

Also, look into using a requirements.txt file, it'll save a lot of time if you keep misplacing the virtualenv.

最后,***不要将您的 venv 命名为virtualenv",而是将其命名为独特的名称 - 否则肯定会造成混淆!

And finally, it's best not to name your venv "virtualenv", name it something unique – otherwise it's guaranteed to confuse!