GitHub仓库中的Python项目包文件夹应包括什么以管理依赖关系?

huangapple go评论67阅读模式
英文:

What should GitHub repo package folder of a Python project include to manage dependencies?

问题

我的程序依赖于Numpy和datetime。我应该将它们包含在模块文件夹中吗?还是可以假定一些基本包已经安装在最终用户的计算机上?

英文:

I have a question that I cannot seem to find the right answer for (perhaps I am articulating it incorrectly).

My program is dependent on Numpy and datetime. should I include those inside the modules folder? Or is it assumed that some of the fundamental packages are already going to be installed on the computer the end user will use?

Layout:

PROGRAM_NAME/
-main
-Readme
--/Modules
  -__init__
  -constants
  -program_name

答案1

得分: 1

以下是翻译好的内容:

Edit:
你可以开始通过向项目添加一个 requirements.txt 文件来开始,尽管如果你想构建一个包,这是过时的建议,但对于小型项目来说是可以的。如果你想构建一个包,可以查看有关 PEP517 的文档:https://peps.python.org/pep-0517/

你还可以使用其他构建工具来构建包,比如 https://github.com/python-poetry/poetry

这个Shell命令将导出你的项目依赖项并保存为名为 requirements.txt 的文件:

pip freeze > requirements.txt

一旦你有了你的 requirements 文件,你可以转到另一台计算机或新的虚拟环境,并运行以下命令:

pip install -r requirements.txt

requirements 文件是项目所有依赖项的列表。这包括依赖项所需的依赖项。它还包含了每个依赖项的具体版本,使用双等号(==)指定。

在这里阅读更多信息:https://realpython.com/lessons/using-requirement-files/

英文:

Edit:
You could start by adding a requirements.txt to your project, although this is outdated advice if you want to build a package, but will be fine for small projects. If you want to build a package, take a look at this documentation about PEP517: https://peps.python.org/pep-0517/

You can also use other build tools to build packages like https://github.com/python-poetry/poetry

This shell command will export your projects dependencies as a file named requirements.txt:

pip freeze > requirements.txt

Once you’ve got your requirements file, you can head over to a different computer or new virtual environment and run the following:

pip install -r requirements.txt

A requirements file is a list of all of a project’s dependencies. This includes the dependencies needed by the dependencies. It also contains the specific version of each dependency, specified with a double equals sign (==).

Read more here: https://realpython.com/lessons/using-requirement-files/

答案2

得分: 0

最佳放置依赖项的地方应该是在一个名为 requirements.txt 的文件中。然后,要安装所有的依赖项,可以使用 pip install -r /path/to/requirements.txt

有关 requirements.txt 的更多信息可以在 pip 文档中找到,链接在这里

英文:

The best place to put dependencies would be in a requirements.txt file. Then to install all the requirements, use pip install -r /path/to/requirements.txt.

More information on requirements.txt can be found here in the pip documentation.

huangapple
  • 本文由 发表于 2023年3月1日 08:11:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75598493.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定