简体   繁体   English

pyinstaller没有名为grpc的模块

[英]pyinstaller No module named grpc

My goal is to build an executable using pyinstaller. 我的目标是使用pyinstaller构建可执行文件。 The python script I am trying to build imports grpc. 我正在尝试构建的python脚本导入grpc。 The following is an example that illustrates the problem called hello.py. 以下是一个示例,说明了名为hello.py的问题。

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

I do pyinstaller hello.py and that produces the expected dist directory. 我做pyinstaller hello.py并生成预期的dist目录。 Then I run it like ./dist/hello/hello and I get error ImportError: No module named grpc. 然后我像./dist/hello/hello一样运行它,我得到错误ImportError: No module named grpc.

So then I installed grpc using pip install grpc . 那么我使用pip install grpc When I rebuild the artifact I now get error Import grpc:No module named gevent.socket . 当我重建工件时,我现在得到错误Import grpc:No module named gevent.socket

Reading online indicated that the correct items to install were actually grpcio and grpcio-tools. 在线阅读表明,正确安装的项目实际上是grpcio和grpcio-tools。 So I tried pip uninstall grpc pip install grpcio and pip install grpcio-tools . 所以我尝试了pip uninstall grpc pip install grpciopip install grpcio-tools Doing this and rebuilding the artifact gave me error ImportError: No module named pkg_resources . 这样做并重建工件给了我错误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 尝试pip install pkg_resources会出错: 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 拥有所有grpcio grpcio-toolsgrpc install会产生同样的错误: 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? 我只是想使用pyinstaller来构建一个依赖于grpc的工件,我该怎么做?

I faced the same issue. 我遇到了同样的问题。 I referred this document: gRPC 我提到了这个文件: gRPC

As per the documentation, first upgrade your pip to version 9 or higher. 根据文档,首先将您的点数升级到版本9或更高版本。

Then use the following commands: 然后使用以下命令:

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

It worked for me! 它对我有用!

I am working on doing a PyInstaller/cx_freeze distributable of a python app using grpc. 我正在使用grpc做一个pyInstaller / cx_freeze可以发布一个python应用程序。

Can you try adding --hidden-import=pkg_resources and see what happens? 你能尝试添加--hidden-import=pkg_resources ,看看会发生什么?

This solved it for me 这解决了我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM