将SWIGged Python库安装到dist-packages / myfoo.py中,而不是dist-packages / myfoo / myfoo.py

时间:2016-09-08 11:19:36

标签: python c++ swig distutils

我有一个像

这样的目录结构
 setup.py
 myfoo/
     myfoo.i
     myfoo.cpp
     myfoo.hpp

setup.py

from distutils.core import setup, Extension

setup(
    name='myfoo',
    ext_modules=[
        Extension(
            '_myfoo',
            [
                'myfoo/myfoo.cpp',
                'myfoo/myfoo.i'
            ],
            swig_opts=['-c++'],
            )
        ],
    version='0.0.1',
    packages=['myfoo'],
    requires=[]
    )

myfoo.hpp

#ifndef MYFOO_HPP
#define MYFOO_HPP

int myfoo();

#endif  // MYFOO_HPP

myfoo.cpp

#include "myfoo.hpp"

#include <iostream>

int myfoo() {
  std::cout << "hey!" << std::endl;
  return 42;
}

运行python setup.py install时,程序包正确构建并安装文件

/usr/local/lib/python2.7/dist-packages/
    _myfoo.so
    myfoo/
        myfoo.py
        myfoo.pyc

默认情况下,只有/usr/local/lib/python2.7/dist-packages/位于$PYTHONPATH,因此来自任何地方的import myfoo都会产生导入错误。要实现这一点,myfoo.py[c]/usr/local/lib/python2.7/dist-packages/都应该在__init__.py中,或者重命名为setup.py。我似乎没有正确地呼叫 class AddressType extends UserType { public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder->add('address'); $builder->add('postCode'); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'PIE10Bundle\Entity\Address', )); } }

任何提示?

1 个答案:

答案 0 :(得分:0)

卸下

packages=['myfoo'],

并添加

py_modules = ['myfoo'],
package_dir = {'' : 'myfoo'}

setup.py就可以了。