sync_proto的报错问题
来源:33-4 配置启动库存服务

曹学习
2021-05-23
运行老师的sync_proto.py报了如下的错误,已经确定虚拟环境中有grpcio,grpcio-tools。且使用命令行直接操作能够正常生成grpc的代码
写回答
2回答
-
bobby
2021-05-24
你这里好像没有进入虚拟环境运行这个代码
112021-05-25 -
曹学习
提问者
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)
032023-05-27
相似问题
add_config_watcher报错
回答 4
docker-compose up 报错
回答 1
import其它proto文件报错
回答 1
python grpc超时机制有些疑问
回答 1
sync_proto
回答 1