简体   繁体   English

python site-packages中的某些包不会显示

[英]Some packages in python site-packages are not displayed

Python包列表

These are the list of packages that are presented in my machine. 这些是我的机器中显示的包列表。 When I tried to use the following python command to get the list the packages with its version, I was only able to see the packages jinja,jsonschema,markupsafe and matplotlib and the package "isapi" is missing. 当我尝试使用以下python命令获取包含其版本的软件包时,我只能看到软件包jinja,jsonschema,markupsafe和matplotlib,并且缺少软件包“isapi”

>>> import pip
>>> ["%s==%s" % (i.key, i.version) for i in pip.utils.pkg_resources.working_set]

Result / Output: 结果/输出:

['jinja2==2.7.3', 'jsonschema==2.5.1', 'markupsafe==0.23', 'matplotlib==1.4.3']

My requirement is to get that ( "isapi" ) in the list too. 我的要求是在列表中也得到( “isapi” )。 Is there any option available ? 有没有可用的选择? Please provide your suggestions here. 请在此提供您的建议。

Thanks in Advance :) 提前致谢 :)

isapi is not a PyPI package and was not installed with pip. isapi 不是PyPI包 ,也没有用pip安装。 You can see this since there is no folder for the package name with a .dist-info suffix. 您可以看到这一点,因为没有带有.dist-info后缀的包名称的文件夹。

The .dist-info folders 1 are created by pip as part of the install process to store the meta information about the PyPI package. .dist-info文件夹1由pip创建,作为安装过程的一部分,用于存储有关PyPI包的元信息。 They essentially contain all the information about a package you can also find on the PyPI website. 它们基本上包含有关包的所有信息,您也可以在PyPI网站上找到它们。 Next to those folders, pip will then add one for the actual package with the real package name 2 that contains the real Python modules. 在这些文件夹旁边,pip将为实际包添加一个包含真实包模块的实际包2

Since your isapi folder obviously did not come from a PyPI package, it came from another source. 由于你的isapi文件夹显然不是来自PyPI包,它来自另一个来源。 This could be for example an external setup utility that just installs the folder in there. 例如,这可以是一个外部设置实用程序,只需在其中安装该文件夹即可。 It's also possible that a different PyPI package installed the folder along as a dependency (not the case for your packages though). 也可能是一个不同的PyPI包将文件夹作为依赖项安装(虽然不是你的包的情况)。 I suggest looking into the folder and the Python modules to get an idea what it does and where it could come from. 我建议查看文件夹和Python模块,以了解它的作用以及它可能来自何处。

Anyway, since it was not installed with pip, pip obviously does not know about it. 无论如何,因为它没有安装pip,pip显然不知道它。 So it does not appear in the package list. 因此它不会出现在包列表中。

Unfortunately, there is no other good way to find out about that module programmatically. 不幸的是,没有其他好方法可以通过编程方式找到该模块。 One possible way would be to simply get a directory listing of the site-packages folder and work through the modules that way. 一种可能的方法是简单地获取site-packages文件夹的目录列表并以这种方式处理模块。 You could also use the pkgutil module to get a list of all modules (including built-in modules) and filter those out that are in the site-packages folder. 您还可以使用pkgutil模块获取所有模块(包括内置模块)的列表,并过滤那些在site-packages文件夹中的模块。 But other than that, there is no other “registy” or something that will keep track of what is in that folder. 但除此之外,没有其他“注册”或其他东西可以跟踪该文件夹中的内容。 And if you think about it, there can't be one since you could always just drop a new folder in there on your own. 如果你考虑一下,就不可能有一个,因为你总是可以自己放一个新的文件夹。


Foot notes : 脚注

1 .dist-info folders were invented with PEP 376 as a way to unify the way distributions are managed. 1 .dist-info文件夹是用PEP 376发明的,用于统一管理分发的方式。

2 Python packages are not required to be spelled exactly like PyPI packages. 2 Python包不需要像PyPI包一样拼写。 This allows for custom casing in the names for PyPI packages (since Python packages should be lower case), or even different names. 这允许在PyPI包的名称中使用自定义大小写(因为Python包应该是小写的),甚至是不同的名称。 For example, the PyPI package name for Beautiful Soup 4 is beautifulsoup4 , but the Python package is just called bs4 . 例如,Beautiful Soup 4的PyPI包名称是beautifulsoup4 ,但Python包名称为bs4

Try this: 试试这个:

import pkgutil
[p[1] for p in pkgutil.iter_modules()]

Should give you names of all installed packages. 应该为您提供所有已安装软件包的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM