pyinstaller No module named grpc

♀尐吖头ヾ 提交于 2021-01-22 04:47:51

问题


My goal is to build an executable using pyinstaller. The python script I am trying to build imports grpc. The following is an example that illustrates the problem called hello.py.

  import grpc
  if __name__ == '__main__':
     print "hello world"

I do pyinstaller hello.py and that produces the expected dist directory. Then I run it like ./dist/hello/hello and I get error ImportError: No module named grpc.

So then I installed grpc using pip install grpc. When I rebuild the artifact I now get error Import grpc:No module named gevent.socket.

Reading online indicated that the correct items to install were actually grpcio and grpcio-tools. So I tried pip uninstall grpc pip install grpcio and pip install grpcio-tools. Doing this and rebuilding the artifact gave me error ImportError: No module named pkg_resources. Trying to pip install pkg_resources gives error: Could not find a version that satisfies the requirement pkg_resources

Having all grpcio grpcio-tools and grpc install gives the same error: Import grpc:No module named gevent.socket

This seems like it should be a very simple task. I simply want to use pyinstaller to build an artifact that has a dependency on grpc, how do I do this?


回答1:


I am working on doing a PyInstaller/cx_freeze distributable of a python app using grpc.

Can you try adding --hidden-import=pkg_resources and see what happens?

This solved it for me




回答2:


I faced the same issue. I referred this document: gRPC

As per the documentation, first upgrade your pip to version 9 or higher.

Then use the following commands:

$ python -m pip install grpcio
$ python -m pip install grpcio-tools

It worked for me!



来源:https://stackoverflow.com/questions/48394486/pyinstaller-no-module-named-grpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!