[英]Why do I need to create a virtual environment for my public Django application?
I've been running my Django project (website) in my local virtual environment. 我一直在本地虚拟环境中运行Django项目(网站)。 However I now want to go live and make the website public - so I've created my remote server on Digital Ocean, and have been following it's tutorial on settings up Django. 但是,我现在想上线并使该网站公开-因此,我在Digital Ocean上创建了我的远程服务器,并一直遵循有关设置Django的教程。 However I've reached this point in the tutorial where it says to create a virtual environment . 但是,在本教程中,我已经达到了创建虚拟环境的目的 。 I thought virtual environments were only used for testing your application offline? 我以为虚拟环境仅用于离线测试您的应用程序? Why do I need a virtual environment for my application running on a remote server? 为什么在运行在远程服务器上的应用程序需要虚拟环境?
I'm not really familiar with Digital Ocean, but creating a virtualenv
should not be strictly required. 我对Digital Ocean并不是很熟悉,但是严格要求不要创建virtualenv
。
It is still a good idea and I'd recommend doing it though. 这仍然是一个好主意,不过我还是建议您这样做。
It will prevent packages required for your application that you install to your virtual environment from messing up other Python applications requirements. 这将防止您安装到虚拟环境的应用程序所需的软件包破坏其他Python应用程序的要求。
For example, let's say your application requires coolpackage 0.9.12
, and another application requires coolpackage 1.1.6
. 例如,假设您的应用程序需要coolpackage 0.9.12
,而另一个应用程序需要coolpackage 1.1.6
。 If there are breaking changes going from 0.9.12
to 1.1.6
, installing coolpackage 1.1.6
will break your first application. 如果从0.9.12
到1.1.6
进行了重大更改,则安装coolpackage 1.1.6
将破坏您的第一个应用程序。
Also, keep in mind that some functionality of your operating system might require specific versions of Python packages (which might even have been installed by some other means than pip
) that you could break in this way. 另外,请记住,操作系统的某些功能可能需要特定版本的Python软件包(甚至可能通过pip
以外的其他方式安装了),您可能会用这种方式破坏它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.