Search code examples
windowscythonpython-3.432-bit

AttributeError compiling Hello World in Cython 3.4 32-bit on Windows


I'm trying to get the Cython Hello World tutorial to work and getting an Attribute Error on the compilation.

My Hello world program, in Python 3.4:

print("Hello World from Cython")

And the setupfile, setupCythonHelloWorld.py:

from distutils.core import setup
from Cython.Build import cythonize
setup(
    ext_modules = cythonize('helloWorld.pyx')
)

At the command line:

py -m setupCythonHelloWorld.py build_ext --inplace running build_ext

Command line returns and error:

Error while finding spec for 'setupCythonHelloWorld.py' (<class 'AttributeError'>: 'module' object has no attribute '__path__')

Here's some details on my computer and install:

  1. Windows 7, 64-bit. (I'm on a Macbook pro using bootcamp, but that shouldn't matter)
  2. Python 3.4, 32-bit version
  3. Regular pip install of modules, mostly from wheels. No Anaconda or Python (x,y).

I've uninstalled and reinstalled all of my windows compilers several times now, which is no fun. I know I need MS C++ 2010 because I have Python 3.4 and I need the compilers to match. There is a lot of information out there on MinGW, but also guidance not to use that compiler as it doesn't match what Python is built with for Windows.

Most most recent reinstall is listed under "Microsoft Visual C++ 10.0 standalone: Windows SDK 7.1 (x86, x64, ia64)". I've also tried a few other ways, including the python 3.4 section of "Compiling Python extensions on Windows."

Any help would be greatly appreciated. I've done a lot of installing and uninstalling of various Windows VS and SDK versions and I'm not much closer than I was 7 hours ago. Thanks.

This is related to a number of other topics:

  • SO "ValueError:['path'] post, but it's likely 64-bit (sorry for no link, I don't have enough points to post more than 2 links)
  • Lots of other cython install posts, but all seem to be related to other systems, including 64-bit, linux, non-Python 3.4 versions, ...

Solution

  • Ok, I punted. I upgraded to Python 3.5 which makes things work much, much easier.

    It was just as easy as explained in the Python 3.5 section of Compiling Python extensions on Windows:

    1. Install Visual C++ 2015 Build Tools
    2. Cython Hello World compiles and runs. Easy.

    I spent over 9 hours today struggling with MS 2010 compilers for Cython on Python 3.4... and never got it to work. I got C++ 2015 Build Tools and Cython using Python 3.5 to run Hello World in under an hour.

    If anyone knows how to make it work I'm interested to know. However, unless something goes horribly wrong with my dependencies I don't think I'm going to look back at Python 3.4 ever again.