您可以在上面的图片中看到,我喜欢记录运行此脚本需要哪些库要求。
(主要是因为我将脚本移至另一台计算机或将其上传到其他计算机时)
但是我的问题并不是所有导入符合pip install命令的名称,这里的关键示例是美丽的。
像干草一样,告诉我这是什么件事来自有点东西。
奖励:如您在项目中所看到的,我们正在使用LXML与BeautifulSoup一起使用,因此我们不需要导入它,但确实需要安装它。有没有“东西”,我可以在py脚本上添加一个“东西”,它会告诉我我需要运行什么要求。
我知道例如,Pyinstaller将包装制作EXE所需的所有库,我想知道是否有一种方法可以像信息模式一样运行Pyinstaller。
编辑:我不想为孔计算机构建一个要求。一个PY文件,而不是孔计算机。

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.
发布评论
评论(4)
通过创建
unignts.txt
文件:您可以将其添加到版本控件(或简单地复制到另一台计算机)和:
它将安装所有在此上列出的包装列出的软件包归档到新环境中。
The usual way to solve that is by creating a
requirements.txt
file:Then you can add it to version control (or simply copy over to another computer) and:
Which will install all the packages listed on the file into the new environment.
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 arequirements.txt
file.Using
pip freeze
exports all installed libraries and is generally not ideal for project basedrequirements.txt
files.您应该定义脚本以所谓的要求,文件。 search pip提供的命令可能是您想要的。但是,只有基于其导入名称,没有可靠的方法来逆转查找软件包名称。您的作案操作应该是:
如果将需求文件与脚本一起放入版本控件中,那么其他人可以从您的工作中获利。
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:
requirements.txt
filepip 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.
谢谢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...