salute-developers / salute-speech

18 stars 7 forks source link

bug: No module named 'synthesis_pb2' #5

Open andchir opened 6 months ago

andchir commented 6 months ago

При запуске python кода выдаёт ошибку, что следующие модули не найдены:

import synthesis_pb2
import synthesis_pb2_grpc

Не нашел таких модулей, как их установить?

Lilneo786 commented 6 months ago

Install Protocol Buffers Compiler (protoc):

https://developers.google.com/protocol-buffers/docs/downloads

Make sure to add the protoc executable to your system's PATH so you can run it from the command line.

Compile Your .proto File:

Use protoc to compile your .proto file into Python code. Replace your_proto_file.proto with the name of your .proto file: css

protoc -I=your_proto_directory --python_out=. your_proto_file.proto

-I=your_proto_directory: Specifies the directory where your .proto file is located. --python_out=.: Specifies the output directory for the generated Python code. The . indicates the current directory.

Generated Modules:

After running the protoc command, it will create two Python files: synthesis_pb2.py and synthesis_pb2_grpc.py. These files contain the generated Python code for your protobuf message types and gRPC service definitions. Import Generated Modules:

In your Python code, you can now import the generated modules as follows:

import synthesis_pb2
import synthesis_pb2_grpc

Make sure that you replace your_proto_directory with the actual directory where your .proto file is located, and your_proto_file.proto with the name of your .proto file.

Once you've successfully generated the Python modules, you should be able to import and use them in your Python code without any errors.

andchir commented 6 months ago

@Lilneo786 Thank you! It works.

Ubuntu:

sudo apt install protobuf-compiler