Python的import文件夹从不导入
Python的import文件夹从不导入
我正在尝试导入这个库-https://github.com/abenassi/Google-Search-API\n我已经尝试过以下方法
\n1. 无法导入Python中的google模块中的search模块
\n2. Python / ImportError:不支持通过文件名导入
\n3. 如何根据完整路径导入模块? \n我仍然无法导入\n
Traceback (most recent call last): File "", line 1, in NameError: name 'google' is not defined
\n即使在本地也是如此\n
>>> import imp >>> google = imp.load_source('google', '/home/arjun/.local/lib/python2.7/site-packages/google/__init__.py') >>> num_page = 3 >>> search_results = google.search("This is my query", num_page) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'search' >>> google
问题出现的原因是可能没有正确安装依赖项或者没有正确导入模块。解决方法是通过以下步骤进行:
1. 确保已按照GitHub上的README.md文件中描述的步骤使用PIP进行安装。
2. 尝试直接从modules/standard_search.py
文件中导入search()
函数,而不是导入整个文件夹。确保依赖项已正确安装。
3. 如果在Python3中安装失败,可能是因为依赖项未正确设置。可以尝试在Python3环境中手动安装selenium和unidecode模块,并在GitHub上报告此问题。
4. 确保在控制台中正确导入模块。使用from google import google
而不是import google
。
5. 如果导入本身不起作用,请检查导入命令和错误消息。可能是因为安装的位置不正确,可以尝试使用正确的pip环境与Python环境匹配,此时通常会引发no module named ...
错误而不是name ' ' not defined
。
6. 如果以上方法都不起作用,可以考虑放弃该库,并寻找其他替代方案。
解决该问题的方法包括正确安装依赖项、正确导入模块以及确保pip环境与Python环境匹配。如果问题仍然存在,可以选择放弃该库并寻找其他解决方案。