4

I am a newbie to cython.

I've the following directory structure.

cython_program/ cython_program/helloworld.py cython_program/lib/printname.py 

helloworld.py:

import lib.printname as name def printname(): name.myname() 

printname.py:

def myname(): print("this is my name") 

setup.py:

from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [ Extension("helloworld", ["helloworld.py"]), Extension("mod", ["./lib/printname.py"]), ] setup( name = 'My Program', cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules ) 

The problem I am having is that when I compile my program using python setup.py build_ext --inplace in the cython_program directory. It does compile the program successfully and generates a printname.c file in the lib folder.

But when I move the printname.py and helloworld.py to a separate folder to make sure that my cython compiled code is running. It gives me the following error ImportError: No module named lib.printname.

Why isn't it compiling the module(lib.printname) also with the main helloworld.py file ?

Note: This works fine if I keep both helloworld.py and printname.py in the same folder.

Thanks in advance.

1
  • 1
    consider accepting your own answer... Commented Oct 16, 2017 at 0:51

1 Answer 1

9

It was a simple issue in setup.py.

Changed this line:

Extension("mod", ["./lib/printname.py"]), 

To This:

Extension("lib.printname", ["./lib/printname.py"]), 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.