2
解析requirements.txt后,让我们假设这是PIP模块列表:如何从其pip需求名称中检索模块的导入名称?
>>> modules_req = ['beautifulsoup4','django-nose','ujson']
>>> for module in modules_req:
... __import__(module)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ImportError: No module named beautifulsoup4
我们怎样才能retreive这些模块即bs4
为beautifulsoup4
的导入名称,并为django_nose
django-nose
,例如?
请问downvoter可以解释closevote和downvote的原因吗? – DhruvPathak
不是downvoter,但为什么不直接在'modules_req'中包含模块导入名称呢? –
@IronFist,因为正如我所提到的那样,它已经从一个requirements.txt文件中解析出来了。上述示例可以是部署前的环境测试。 – DhruvPathak