Mikael
Mikael

Reputation: 1

Cython Examples Failing

I tried to run the examples in page:

http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html#the-basics-of-cython

on Windows 10 using Visual studio 2017 and python 3.53 x64.

Compilation was OK. But when I try to import the generated pyd (dll) into Python 3.53 (x64), I get an error.

The generated pyd file and the rest of the files are all in the same folder.

Has any one managed to run successfully those 3 examples in the above link under Python 3.5 with Visual Studio 2017 ?

Upvotes: 0

Views: 53

Answers (1)

abarnert
abarnert

Reputation: 366213

The problem is just that you're not importing the modules correctly.

Just as you use import spam, not import spam.py, for a Python module, you use import spam, not import spam.cp35-win_amd64 for an extension module.

Notice that the example you linked to does it like that:

>>> import helloworld
Hello World

If you're wondering why you got exactly the error you did: the - character isn't part of a name, it's an arithmetic operator. So you were telling it you want to import the module cp35 - win_amd64 from the package spam, and that confused the parser, so it gave you a SyntaxError.


Since you asked about your particular toolset: Yes, those all work together. In fact, as documented on the wiki, all Python 3.5 installers from python.org are built with Visual C++ 14.0, which is the compiler that comes with Visual Studio 2017, and come with a distutils that can automatically detect and use it. (If you have an old version of setuptools—type pip show setuptools to see if the version number is at least 34.4.0—it can cause problems, but those problems prevent Cython packages from compiling at all.)

Upvotes: 1

Related Questions