PyCharm与命令行的虚拟环境 [英] Virtual Environment from PyCharm vs. Command Line

查看:530
本文介绍了PyCharm与命令行的虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对创建Python应用程序还很陌生.我自欺欺人地使用PyCharm制作了一些小型教程和应用程序,并且始终使用Virtualenv环境创建了一个新项目,最后在我的项目文件夹下创建了一个"venv"文件夹.我对此没有任何问题,但我又没有做任何大型项目.

I am fairly new to creating Python applications. I have fooling around with some small tutorials and applications using PyCharm and have always created a new project using the Virtualenv environment, ending up with a "venv" folder under my project folder. I have not had any problems with this, but then again I have not done any large projects.

但是,我一直想学习Flask,并希望尝试以正确的方式创建一个新的Flask项目.我在许多教程中看到,人们正在使用(Windows/Linux)命令行创建(并激活)虚拟环境,尽管他们正在使用PyCharm,但我只是想知道两者之间的区别是什么?

However, I have been wanting to learn Flask want to try to create a new Flask project the proper way. I see in many tutorials that people are creating (and activating) the virtual environment from the (Windows/Linux) Command Line instead even though they are using PyCharm and I was just wondering what the difference is?

当我在用Virtualenv创建的PyCharm项目中工作时,我不会在操作前激活venv.这是错误的还是由PyCharm处理?如果venv是从命令行创建的,该怎么办?如果在该项目上工作,它是否仍由PyCharm处理(激活).文件夹结构又如何呢?这受虚拟环境创建方式的影响吗?在虚拟环境中创建Flask项目时,在哪里可以找到设置/文件夹结构的最佳实践"?

When I work on a project in PyCharm, created with Virtualenv, I do not activate the venv before working on it. Is this wrong or is this something that is handled by PyCharm? What if the venv is created from a Command Line? Is it still handled (activated) by PyCharm if working on the project there. And what about the folder structure? Is this affected by how the virtual environment is created? Is there somewhere I can find some "best practices" for the setup / folder structure when creating Flask project within a Virtual Environment?

推荐答案

如果将PyCharm配置为使用一个并告知其位置(更具体地讲,VirtualEnv中各个Python二进制文件的位置),PyCharm会为您激活VirtualEnv.

PyCharm activates the VirtualEnv for you if it is configured to use one and told where it is (more specifically, where the respective Python binary in the VirtualEnv is).

手动创建的VirtualEnv和PyCharm创建的虚拟Env之间并没有真正的区别. (除了您选择创建的框架之外,以防与PyCharm配置的框架不同.)

There's no real difference between manually created VirtualEnvs and ones created by PyCharm. (Apart from the framework you select to create one in case this is different from what PyCharm is configured with.)

如果需要,您可以手动创建一个,然后将PyCharm指向它.在创建项目期间或稍后使用设置"对话框(请参阅设置->项目->项目解释器).然后,它将进行不同的处理,并且在IDE中进行操作时也会为您激活它.

If you want, you can just create one manually and then point PyCharm to it. Either during creation of the project or later using the Settings dialog (see Settings -> Project -> Project Interpreter). It will then treat it no differently and also activate it for you when working inside the IDE.

这篇关于PyCharm与命令行的虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆