-1

I am using python 3.53 cython 0.28.2 and Visual studio compiler 2017. The example was taken from:

http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html#cython-hello-world

I am trying to compile a simple helloworld.pyx

print ('hello world')

using visualstudio 2017. I tried two setup.py files

1st setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("helloworld", ["helloworld.pyx"])]
)

2nd setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

both succeeded using

python setup.py build_ext --inplace,  

and generated the following dll:

helloworld.cp35-win_amd64.pyd

But when I import the generated pyd file using:

import helloworld.cp35-win_amd64

I get

import helloworld.cp35-win_amd64

                     ^

SyntaxError: invalid syntax

Renaming the pyd file to shorter name without - or _ did not work.

Any suggestions are appreciated.

Adam
  • 3
  • 5

1 Answers1

0

The solution is simple:

keep the generated pyd file name unchanged. Very important.

in the python script use import the pyd name until first dot.

in the above case

import helloworld

if you still get unresolved import error you can find a solution in this link: Unresolved Import Issues with PyDev and Eclipse

Adam
  • 3
  • 5