Django是否有相当于Rails的“捆绑安装”?

时间:2022-01-14 12:29:32

One thing I like about Rails projects is that when deploying to a remote server, if everything is set up correctly you can just do:

我喜欢Rails项目的一件事是,当部署到远程服务器时,如果一切设置正确,你可以这样做:

$: bundle install

And the system will install the various dependencies (ruby gems) needed to run the project.

系统将安装运行项目所需的各种依赖项(ruby gems)。

Is there something similar for Python/Django?

Python / Django有类似的东西吗?

2 个解决方案

#1


11  

You can freeze requirements. This generates a list of all the Python modules that your project needs. I believe bundle is similar in concept.

您可以冻结要求。这将生成项目所需的所有Python模块的列表。我认为捆绑在概念上是相似的。

For example:

例如:

virtualenv --no-site-packages myproject_env # create a blank Python virtual environment
source myproject_env/bin/activate # activate it
(myproject_env)$ pip install django # install django into the virtual environment
(myproject_env)$ pip install other_package # etc.
...
(myproject_env)$ pip freeze > requirements.txt

The last line generates a text file will all the packages that were installed in your custom environment. You can use that file to install the same requirements on other servers:

最后一行生成一个文本文件,其中包含自定义环境中安装的所有软件包。您可以使用该文件在其他服务器上安装相同的要求:

pip install -r requirements.txt

Of course you don't need to use pip, you can create the requirements file by hand; it doesn't have any special syntax requirements. Just a package and (possibly) version identifier on each line. Here is a sample of a typical django project with some extra packages:

当然你不需要使用pip,你可以手工创建需求文件;它没有任何特殊的语法要求。每行只是一个包和(可能)版本标识符。这是一个典型的django项目的示例,其中包含一些额外的包:

Django==1.4
South==0.7.4
Werkzeug==0.8.3
amqplib==1.0.2
anyjson==0.3.1
celery==2.5.1
django-celery==2.5.1
django-debug-toolbar==0.9.4
django-extensions==0.8
django-guardian==1.0.4
django-picklefield==0.2.0
kombu==2.1.4
psycopg2==2.4.5
python-dateutil==2.1
six==1.1.0
wsgiref==0.1.2
xlwt==0.7.3

#2


3  

The closest is probably virtualenv, pip and a requirements file. With those 3 ingredients is quite easy to write a simple bootstrap scripts.

最接近的可能是virtualenv,pip和一个需求文件。使用这3个成分很容易编写简单的引导脚本。

More demanding and complex is buildout. But I would only go for it if virtualenv and pip are not sufficient.

扩建要求更高,更复杂。但是,如果virtualenv和pip不够,我只会选择它。

And if you extend this approach with fabric and optional cuisine, you already have your project deployment automated. Check out these links for more information:

如果您使用结构和可选菜肴扩展此方法,您已经自动完成了项目部署。查看这些链接以获取更多信息:

#1


11  

You can freeze requirements. This generates a list of all the Python modules that your project needs. I believe bundle is similar in concept.

您可以冻结要求。这将生成项目所需的所有Python模块的列表。我认为捆绑在概念上是相似的。

For example:

例如:

virtualenv --no-site-packages myproject_env # create a blank Python virtual environment
source myproject_env/bin/activate # activate it
(myproject_env)$ pip install django # install django into the virtual environment
(myproject_env)$ pip install other_package # etc.
...
(myproject_env)$ pip freeze > requirements.txt

The last line generates a text file will all the packages that were installed in your custom environment. You can use that file to install the same requirements on other servers:

最后一行生成一个文本文件,其中包含自定义环境中安装的所有软件包。您可以使用该文件在其他服务器上安装相同的要求:

pip install -r requirements.txt

Of course you don't need to use pip, you can create the requirements file by hand; it doesn't have any special syntax requirements. Just a package and (possibly) version identifier on each line. Here is a sample of a typical django project with some extra packages:

当然你不需要使用pip,你可以手工创建需求文件;它没有任何特殊的语法要求。每行只是一个包和(可能)版本标识符。这是一个典型的django项目的示例,其中包含一些额外的包:

Django==1.4
South==0.7.4
Werkzeug==0.8.3
amqplib==1.0.2
anyjson==0.3.1
celery==2.5.1
django-celery==2.5.1
django-debug-toolbar==0.9.4
django-extensions==0.8
django-guardian==1.0.4
django-picklefield==0.2.0
kombu==2.1.4
psycopg2==2.4.5
python-dateutil==2.1
six==1.1.0
wsgiref==0.1.2
xlwt==0.7.3

#2


3  

The closest is probably virtualenv, pip and a requirements file. With those 3 ingredients is quite easy to write a simple bootstrap scripts.

最接近的可能是virtualenv,pip和一个需求文件。使用这3个成分很容易编写简单的引导脚本。

More demanding and complex is buildout. But I would only go for it if virtualenv and pip are not sufficient.

扩建要求更高,更复杂。但是,如果virtualenv和pip不够,我只会选择它。

And if you extend this approach with fabric and optional cuisine, you already have your project deployment automated. Check out these links for more information:

如果您使用结构和可选菜肴扩展此方法,您已经自动完成了项目部署。查看这些链接以获取更多信息: