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

mac上跑api demo,报错ModuleNotFoundError: No module named 'chatglm_cpp._C' #91

Closed
xwdreamer opened this issue Aug 12, 2023 · 2 comments

Comments

@xwdreamer
Copy link

按照文档执行,前面的所有案例都跑通了,就测试api的时候报错ModuleNotFoundError: No module named 'chatglm_cpp._C'

我的环境是macbook pro m2环境。

参考了前面的https://github.com/li-plus/chatglm.cpp/issues/14这个案例,但是依然还没有解决问题。

请问我应该如何处理这个错误

 chatglm.cpp % MODEL=./chatglm2-ggml.bin uvicorn chatglm_cpp.openai_api:app --host 127.0.0.1 --port 8000

Traceback (most recent call last):
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/bin/uvicorn", line 8, in <module>
    sys.exit(main())
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/main.py", line 410, in main
    run(
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/main.py", line 578, in run
    server.run()
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/config.py", line 473, in load
    self.loaded_app = import_from_string(self.app)
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/importer.py", line 24, in import_from_string
    raise exc from None
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "/Users/xuwei/opt/anaconda3/envs/pytorch_m1/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Volumes/data/huggingface/chatglm.cpp2/chatglm.cpp/chatglm_cpp/__init__.py", line 6, in <module>
    import chatglm_cpp._C as _C
ModuleNotFoundError: No module named 'chatglm_cpp._C'
@li-plus
Copy link
Owner

li-plus commented Aug 12, 2023

尝试下cd到别的路径下运行,在chatglm.cpp目录下执行,包名会跟仓库里的chatglm_cpp文件夹冲突

@xwdreamer
Copy link
Author

感谢答复,切换目录到example以后就好了

% pwd
/Volumes/data/huggingface/chatglm.cpp2/chatglm.cpp/examples
% ls -l
total 48
drwxr-xr-x@ 3 xuwei  staff    96  8 12 12:47 __pycache__
-rw-r--r--@ 1 xuwei  staff  6816  8 11 18:24 api_demo.py
-rw-r--r--@ 1 xuwei  staff  3379  8 11 18:24 cli_chat.py
-rw-r--r--@ 1 xuwei  staff   182  8 11 18:24 langchain_client.py
-rw-r--r--@ 1 xuwei  staff   673  8 11 18:24 openai_client.py
-rw-r--r--@ 1 xuwei  staff  3169  8 11 18:24 web_demo.py


MODEL=/Volumes/data/huggingface/chatglm.cpp2/chatglm.cpp/chatglm2-ggml.bin uvicorn chatglm_cpp.openai_api:app --host 127.0.0.1 --port 8000


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