Py学习  »  Python

使用cx_freeze将grpc python代码设置为exe:没有名为“pkg_resources”的模块

Raymond • 5 年前 • 1444 次点击  

我用python制作grpc服务器。我的目标是使用cx_freeze构建一个可执行文件。

在使用cx_freeze生成greeter_server.exe之后,在运行greeter_server.exe时遇到此错误。

Traceback (most recent call last):  
File “greeter_server.py", line 19, in <module>   
File “c:\users\User\anaconda3\envs\tensorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module     exec(bytecode, module.__dict__)   
File “site-packages\grpc\__init__.py", line 22, in <module>  
File “src\python\grpcio\grpc\_cython\cygrpc.pyx", line 18, in init grpc._cython.cygrpc 
ModuleNotFoundError: No module named ‘pkg_resources'

我的setup.py是这样的。

import sys
from cx_Freeze import setup, Executable

build_exe_options = {}

setup(
    name='py freeze test',
    version='0.0.1',
    description="greeter_server function test",
    author="ray",
    options={'build_exe':build_exe_options},
    executables=[Executable("greeter_server.py")],
)

我试了很多次。

PIP安装组 PIP安装GRPCIO pip安装grpcio工具

pip安装--升级setuptools pip安装--升级分发

但是当我尝试pip install–upgrade distribute时,我遇到了这个错误。

Collecting distribute
  Using cached https://files.pythonhosted.org/packages/5f/ad/1fde06877a8d7d5c9b60eff7de2d452f639916ae1d48f0b8f97bf97e570a/distribute-0.7.3.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\__init__.py", line 2, in <module>
        from setuptools.extension import Extension, Library
      File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\extension.py", line 5, in <module>
        from setuptools.dist import _get_unpatched
      File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\dist.py", line 7, in <module>
        from setuptools.command.install import install
      File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\command\__init__.py", line 8, in <module>
        from setuptools.command import install_scripts
      File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\command\install_scripts.py", line 3, in <module>
        from pkg_resources import Distribution, PathMetadata, ensure_directory
      File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\pkg_resources.py", line 1518, in <module>
        register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
    AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\

我用的是蟒蛇3-5.2.0,蟒蛇3.6.7。(因为我必须使用tensorflow)

任何帮助都将不胜感激。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/42980
 
1444 次点击  
文章 [ 2 ]  |  最新文章 5 年前