[pypy-dev] pypy about c-extension

KaShining mail2shine at qq.com
Mon Nov 4 09:13:41 CET 2013


+++++++++++++++++++
addressbook.proto
package tutorial;

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

message AddressBook {
  repeated Person person = 1;
}

 /usr/local/bin/protoc -I=./ --cpp_out=./ ./addressbook.proto
 gen  addressboo.pb.h and addressboo.pb.cc

 
addressbook.c:
 #include <Python.h>

static PyMethodDef podMethods[] = {
   {NULL, NULL, 0, NULL}        /* Sentinel */
 };

PyMODINIT_FUNC
 initpodpb(void)
 {
   PyObject *m;

  m = Py_InitModule("podpb", podMethods);
   if (m == NULL)
     return;
 }

 

setup.py
 
import os
 import platform

from setuptools import setup, find_packages
 from distutils.core import setup, Extension

setup(
     ext_modules=[Extension('podpb',
 sources=['./addressbook.c','./addressbook.pb.cc'], libraries=['protobuf'])]
     )

 

 python setup.py build
gen build/lib.linux-x86_64-2.7/podpbpypy.so

then in my test.py
import podpbpypy

throw err:

ImportError: No module named podpbpypy

 

 




------------------ Original ------------------
From:  "Armin Rigo";<arigo at tunes.org>;
Date:  Mon, Nov 4, 2013 04:08 PM
To:  "KaShining"<mail2shine at qq.com>; 
Cc:  "pypy-dev"<pypy-dev at python.org>; 
Subject:  Re: [pypy-dev] pypy about c-extension



Hi,

On Mon, Nov 4, 2013 at 9:04 AM, KaShining <mail2shine at qq.com> wrote:
> import podpbpypy
> ImportError: No module named podpbpypy
>
> seen can't find podpbpypy.so

There is no point repeating what you already said.  I'm asking, how
did you build the .so in the first place.


Armin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20131104/bd6304dc/attachment.html>


More information about the pypy-dev mailing list