python - setup.py 与 requirements.txt 区别
迷茫
迷茫 2017-04-18 09:33:40
0
3
590

在阅读Kenneth Retiz写的ptyhon最佳实践文章中关于如何构建一个好的目录结构的时候,发现有这样一个问题,可以同时存在setup.py文件以及requirements.txt文件,想请问一下这两者之间有什么区别与联系。
例如有下面这样的一个flask应用目录结构,setup.py与requirements.txt两个文件同时存在是否有必要?

├── app ├── docs ├── test ├── config.py ├── manage.py ├── requirements.txt ├── setup.py ├── Makefile ├── README.md └── LICENSE
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (3)
伊谢尔伦

Whether this question is necessary actually depends on the nature of the project. Generally speaking, there will be both, and it is best to have both.

setup.pyThis file is used to manage modules. You can package your project as a module and upload it to pypi. You can also put the project as a module into the python system loading module directory.

requiremens.txtThis file lists the non-project dependencies that your project references. Other than that, it has no other function.

Therefore, it can be seen that there is no conflict between these two projects, and there is a great need to coexist.

  • It is essential if your project needs to be saved as a system module or can be installed as a system commandsetup.py

  • If your project can be run directly, thenrequirements.txtis also essential.

  • If you need both functions, then both files must be included.

Do you need both functions?

There must be one, and there are many more. For example, Flask supports two methods:

  • Start as a system command. A new Click package has been added in Flask 0.11.1, which allows you to run it as a command after setup

  • Direct operation, traditionalFlask启动方式一般就是app.run()或者python manage.py runserver

Hope it’s helpful to the questioner.


Added:

In fact,setup.py里面也会有依赖的列表,所以,在 setup 的时候无需担心会和requirements.txt关联,因为不需要关联这个,作者已经在setup.pywill also have a list of dependencies, so there is no need to worry about being associated with

during setup, because there is no need to associate this, the author has already written it in .
    小葫芦

    I saw that requirements.txt is a must. It declares which third-party libraries are introduced into your project. As a flask web application setup.py doesn't seem to make sense. . .

      Ty80

      setup.py是安装你自己写的模块,一般依靠执行sudo python setup.py install,

      requirements.txt是指明这个模块所依赖的模块,一般执行sudo pip install -r requirements.txtTo install dependent modules.

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!