sync_proto的报错问题

来源:33-4 配置启动库存服务

曹学习

2021-05-23

图片描述
运行老师的sync_proto.py报了如下的错误,已经确定虚拟环境中有grpcio,grpcio-tools。且使用命令行直接操作能够正常生成grpc的代码

写回答

2回答

bobby

2021-05-24

你这里好像没有进入虚拟环境运行这个代码

1
1
曹学习
老师,追加问题贴在二楼了。这个我确实不太理解为什么不行
2021-05-25
共1条回复

曹学习

提问者

2021-05-25

(peewee-mall) E:\JetBrains\pythonProject\mxshop_srvs\tools>python sync_proto.py

C:\Users\think\AppData\Roaming\Python\Python38\python.exe: Error while finding module specification for 'grpc_tools.protoc' (ModuleNotFoundError: No module named 'g

rpc_tools')

[]


进入虚拟环境下执行了,但不知道为啥还是给退到全局环境下了,代码中workon命令已经修改成我自己的虚拟环境了,但还是不行

class PyProtoGenerator:
    def __init__(self, python_dir):
        self.python_dir = python_dir

    def generate(self):
        with cd(self.python_dir):
            files = proto_file_list(self.python_dir)
            subprocess.call("workon peewee-mall", shell=True)
            for file in files:
                command = f"python -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I. {file}"
                subprocess.call(command)

            #查询生成的py文件并添加上 from .
            py_files = generated_pyfile_list(self.python_dir)
            for file_name in py_files:
                replace_file(file_name)
            print(py_files)


0
3
bobby
回复
0沉默使者0
赞一个
2023-05-27
共3条回复

Go+Python打造电商系统 自研微服务框架 抓紧高薪机遇

快速转型Go工程师,成为具备双语言后端能力的开发者

510 学习 · 530 问题

查看课程