How can I use protocol buffers for Python on windows?

时间秒杀一切 提交于 2019-11-30 07:10:47

How can I correctly install and run protocol buffers from Python on Windows?

Like any other package, you have to actually install it if you want it to be installed. If you just try to run with the package sitting in your source directory, it might work, but most packages don't work that way; you tend to get things like the top-level package importing and then failing a few lines down when it tries to import something else… exactly as you're seeing.

I believe an installable package comes in the main download package from GoogleCode. At least it does for the source packages, if not the win32 package. And inside the python directory are complete instructions for installing it. Basically:

C:\path\to\protobuf-2.5.0> cd python
C:\path\to\protobuf-2.5.0\python> python setup.py build
C:\path\to\protobuf-2.5.0\python> python setup.py test
C:\path\to\protobuf-2.5.0\python> python setup.py install

But if that doesn't come with the win32 pre-built package, or you don't have it lying around anymore, or you just prefer to install off PyPI, it's also available there. So, assuming you've got pip installed:

pip install protobuf
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!