问题描述
我在使用 .proto 文件中的 grpc_tools 包生成代码时遇到问题:
Traceback (most recent call last):
File "somepath\run_codegen.py",line 16,in <module>
generate()
File "somepath\run_codegen.py",line 6,in generate
from grpc_tools import protoc
File "C:\python39\lib\site-packages\grpc_tools\protoc.py",line 22,in <module>
from grpc_tools import _protoc_compiler
我已经从 requirements.txt 安装了这些依赖项:
Flask~=1.1
grpcio
grpcio-tools
protobuf
from grpc_tools import protoc
def generate():
protoc.main((
'','-I./FinancialDataScraper/protos','--python_out=./FinancialDataScraper/Generated','--grpc_python_out=./FinancialDataScraper/Generated','./FinancialDataScraper/protos/quotes.proto'
))
generate()
我不知道是否应该明确使用 grpcio 和 grpcio_tools 包的版本号,或者这与 python 本身有关,或者我错过了一些其他依赖项安装。
解决方法
事实上,问题是因为我在我的环境之外执行了脚本,而环境没有被激活。