Get all modules/packages used by a python project

回眸只為那壹抹淺笑 提交于 2019-12-03 04:55:50

问题


I have a python GUI application. And now I need to know what all libraries the application links to. So that I can check the license compatibility of all the libraries.

I have tried using strace, but strace seems to report all the packages even if they are not used by the application.

And, I tried python ModuleFinder but it just returns the modules that are inside python2.7 and not system level packages that are linked.

So is there any way I can get all the libraries that are linked from my application?


回答1:


You can give a try to the library https://github.com/bndr/pipreqs found following the guide https://www.fullstackpython.com/application-dependencies.html


The library pipreqs is pip installable and automatically generates the file requirements.txt. It contains all the imports libraries with versions you are using in the virtualenv or in the python correctly installed.

Just type:

pip install pipreqs
pipreqs /home/project/location

It will print:

INFO: Successfully saved requirements file in /home/project/location/requirements.txt

In addition it is compatible with the pip install -r command: if you need to create a venv of your project, or update your current python version with compatible libraries, you just need to type:

pip install -r requirements.txt

I had the same problem and this library solved it for me. Not sure if it works for multiple layers of dependencies i.e. in case you have nested level of dependent libraries.

-- Edit - Update:

If looking for a more sophisticated version manager, please consider as well pyvenv https://github.com/pyenv/pyenv. It blends virtualenv and pipreqs in the same tool, with some improvements over the version specification of pipreqs.




回答2:


Install yolk with:

pip install yolk

Call the following to get the list of eggs in your environment:

yolk -l

Alternatively, you can use snakefood for graphing your dependencies, as answered in this question.

You could try going into the site-packages folder where the unpacked eggs are stored, and running this:

ls -l */LICENSE*

That will give you a list of the licence files for each project (if they're stored in the root of the egg, which they usually are).



来源:https://stackoverflow.com/questions/35796968/get-all-modules-packages-used-by-a-python-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!