Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于运行app.py时的库缺失报错 #15

Open
uminosaki opened this issue May 28, 2021 · 1 comment
Open

关于运行app.py时的库缺失报错 #15

uminosaki opened this issue May 28, 2021 · 1 comment

Comments

@uminosaki
Copy link

uminosaki commented May 28, 2021

使用pip install -r requirements.txt安装库时出现了许多报错,故手动逐条安装requirements.txt中的库。但是运行app.py时依然出现了数次库缺失的报错,都按照报错内容安装了对应库。但最终这个“google”库缺失的问题无法解决,因为通过pip list,我可以确定“google”库正确安装了。希望获知原因。python 版本3.8.5
Traceback (most recent call last): File "D:\Applition\MST\AnimeSearcher-master\app.py", line 1, in <module> from api.router import APIRouter File "D:\Applition\MST\AnimeSearcher-master\api\router.py", line 9, in <module> from api.core.agent import Agent File "D:\Applition\MST\AnimeSearcher-master\api\core\agent.py", line 8, in <module> from api.core.scheduler import Scheduler File "D:\Applition\MST\AnimeSearcher-master\api\core\scheduler.py", line 7, in <module> from api.core.loader import ModuleLoader File "D:\Applition\MST\AnimeSearcher-master\api\core\loader.py", line 15, in <module> class ModuleLoader(object): File "D:\Applition\MST\AnimeSearcher-master\api\core\abc.py", line 11, in singleton instance = cls() File "D:\Applition\MST\AnimeSearcher-master\api\core\loader.py", line 33, in __init__ self.load_full_module(module) File "D:\Applition\MST\AnimeSearcher-master\api\core\loader.py", line 40, in load_full_module self.load_search_module(module) File "D:\Applition\MST\AnimeSearcher-master\api\core\loader.py", line 47, in load_search_module py_module = import_module(module) File "C:\Users\Misachu\anaconda3\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "D:\Applition\MST\AnimeSearcher-master\api\danmaku\bilibili\__init__.py", line 4, in <module> from google.protobuf.json_format import MessageToDict ModuleNotFoundError: No module named 'google'

@zaxtyson
Copy link
Owner

zaxtyson commented May 28, 2021

首先, google 这个库, 并不是 Google 的, 是这个哥们创建的 https://pypi.org/user/mvilas/, 然后就导致了一些悲剧

先卸掉它, 再安装 protobuf

pip uninstall google
pip install protobuf

安装之后, 包的结构是这样的

site-packages/
    google/
        protobuf/
            __init__.py

protobuf 这个包, 放在 google 文件夹下, 但是 google 这个目录缺少 __init__.py , 导致有些环境下, 它无法被正确识别为一个package, 就导致 ModuleNotFoundError了. 后来有人提交 PR 修复了这个问题, 但是命名空间的改变又导致了 google-cloud 这个库出了问题 emmm

见: protocolbuffers/protobuf#1296

如果卸掉 google 这个非官方库再安装 protobuf 还是有问题, 可以手动创建这个文件

${your_python_path}\site-packages\google\__init__.py

如果还是不行, 就在这个文件里面写上

try:
  __import__('pkg_resources').declare_namespace(__name__)
except ImportError:
  __path__ = __import__('pkgutil').extend_path(__path__, __name__)

关于这个问题, 可以看StackOverflow的讨论: https://stackoverflow.com/questions/38680593/importerror-no-module-named-google-protobuf 或者是 protobuf 的 issue, 总之就是非常离谱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants