python pip安装查找器

发布于 2025-02-04 07:12:49 字数 557 浏览 3 评论 0 原文

您可以在上面的图片中看到,我喜欢记录运行此脚本需要哪些库要求。
(主要是因为我将脚本移至另一台计算机或将其上传到其他计算机时)
但是我的问题并不是所有导入符合pip install命令的名称,这里的关键示例是美丽的。 像干草一样,告诉我这是什么件事来自有点东西。

奖励:如您在项目中所看到的,我们正在使用LXML与BeautifulSoup一起使用,因此我们不需要导入它,但确实需要安装它。有没有“东西”,我可以在py脚本上添加一个“东西”,它会告诉我我需要运行什么要求。
我知道例如,Pyinstaller将包装制作EXE所需的所有库,我想知道是否有一种方法可以像信息模式一样运行Pyinstaller。



编辑:我不想为孔计算机构建一个要求。一个PY文件,而不是孔计算机。

demo

So As you can see in the above pic I like to document what library requirements are needed to run this script.
(mostly for when I move the script to another computer or upload it to someone else)
But my problem is not all imports match the name of there pip install command, key example here being BeautifulSoup.
So I would like to know if there is a python command to look up a library name from it's import.
Like hay, tell me what packadge this import is from kinda thing.

Bonus: As you can see in the project we are using lxml with BeautifulSoup so we don't need to import it, but it does need to be installed. Is there a "thing" that I can just chuck a py script at and it will tell me what requirements I need to run it.
I know that pyinstaller for example will package all the librarys it needs to make the exe, I wonder if there is a way I can run pyinstaller in like an info mode.

Edit: I don't want to build a requirements.txt for the hole computer, just one for the script i'm working on currently.
Or just requirements.txt for only one py file, not the hole computer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

瑾兮 2025-02-11 07:12:49

通过创建 unignts.txt 文件:

pip freeze > requirements.txt

您可以将其添加到版本控件(或简单地复制到另一台计算机)和:

pip install -r requirements.txt

它将安装所有在此上列出的包装列出的软件包归档到新环境中。

The usual way to solve that is by creating a requirements.txt file:

pip freeze > requirements.txt

Then you can add it to version control (or simply copy over to another computer) and:

pip install -r requirements.txt

Which will install all the packages listed on the file into the new environment.

栖竹 2025-02-11 07:12:49

pipreqs 库(特定程序并导出到 sumplions.txt 文件。

使用 pip冻结 enforts 所有已安装的库,通常不适合基于项目的 unignts.txt 文件。

The pipreqs library (from pypi) is used to collect imported libraries for the specific program and export to a requirements.txt file.

Using pip freeze exports all installed libraries and is generally not ideal for project based requirements.txt files.

始终不够爱げ你 2025-02-11 07:12:49

您应该定义脚本以所谓的要求,文件 search pip提供的命令可能是您想要的。但是,只有基于其导入名称,没有可靠的方法来逆转查找软件包名称。您的作案操作应该是:

  1. 确定需要哪些
  2. 包装添加需要的
  3. 软件包。 /code>,

如果将需求文件与脚本一起放入版本控件中,那么其他人可以从您的工作中获利。

You should define the requirements for a script to run in a so called requirements file. The search command provided by pip may be what you are looking for. But there is no reliable way to reverse lookup package names just based on their import name. Your modus operandi should be:

  1. Determine what packages you need
  2. Add needed packages into requirements.txt file
  3. Install the dependencies (preferably within a virtual environment or similar) via pip install -r requirements.txt

If you put the requirements file into version control along with your script others can profit from your work much easier.

海风掠过北极光 2025-02-11 07:12:49

谢谢S3Dev
pipreqs 工作。
PIPREQS C:\ myProjectFolder
将仅对myprojectFolder文件夹中的python文件提出要求。很抱歉在这里崭露头角,但这是一个次评论,我不知道如何“给出要点”解决我的问题。因此,我将标记为解决...

Thank you to S3DEV
pipreqs worked.
pipreqs C:\MyProjectFolder
Will make a requirements.txt for only the python files in the MyProjectFolder folder and only the scrips in that folder, not the hole computer.
It will save the requirements.txt to the same folder.

Also sorry for being new here, but this was a sub comment and I don't know how to "give the points" for solving my issues to S3DEV. So I'll just mark this one as solved...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文