Discussion:
How do you run Cython in Windows?
Canon
2012-08-16 20:31:48 UTC
Permalink
How do I run or compile Cython? So far I have been unable to do either.

Some background:
Windows XP, 32-bit machine
downloaded Python (x,y) 2.7.2.3
(http://code.google.com/p/pythonxy/wiki/Downloads)
I checked the boxes in the python package that would included Cython 0.16
and the MinGW compiler in the installation

I try to follow the steps in this Cython tutorial
(http://docs.cython.org/src/userguide/tutorial.html) but get errors. The
tutorial does not specify where these steps should be performed, maybe it
doesn't matter?

1) I open up IDLE and write:
print "hello world"
2) I save this program as helloworld.pyx, and then close IDLE
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"])]
)

4) after pressing enter I get the following error:

Traceback (most recent call last):
File "<pyshell#6>", line 3, in <module>
ext_modules = [Extension("helloworld",["helloworld.pyx"])]
File "C:\Python27\lib\distutils\core.py", line 140, in setup
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: --help [cmd1 cmd2 ...]
or: --help-commands
or: cmd --help

error: no commands supplied


5) If I go onto the next step and type:

$ python setup.py build_ext --inplace

Then I get a syntax error on the dollar sign



What is going on? I get the same errors if I do steps 3-5 in the cmd.exe
Shell.
import pyximport; pyximport.install()
import helloworld
(I do this in IDLE)

and the result is a long list of errors.


What is going on???
Warren Weckesser
2012-08-17 01:09:25 UTC
Permalink
Post by Canon
How do I run or compile Cython? So far I have been unable to do either.
Windows XP, 32-bit machine
downloaded Python (x,y) 2.7.2.3 (
http://code.google.com/p/pythonxy/wiki/Downloads)
I checked the boxes in the python package that would included Cython 0.16
and the MinGW compiler in the installation
I try to follow the steps in this Cython tutorial (
http://docs.cython.org/src/userguide/tutorial.html) but get errors. The
tutorial does not specify where these steps should be performed, maybe it
doesn't matter?
print "hello world"
2) I save this program as helloworld.pyx, and then close IDLE
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"])]
)
File "<pyshell#6>", line 3, in <module>
ext_modules = [Extension("helloworld",["helloworld.pyx"])]
File "C:\Python27\lib\distutils\core.py", line 140, in setup
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: --help [cmd1 cmd2 ...]
or: --help-commands
or: cmd --help
error: no commands supplied
The tutorial tells you to *create a file* called setup.py containing:

from distutils.core import setupfrom distutils.extension import
Extensionfrom Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("helloworld", ["helloworld.pyx"])])


and then, in a terminal (i.e. a DOS prompt, in the directory where setup.py
is saved), run the command
Post by Canon
python setup.py build_ext --inplace
Try that, and if you don't get any errors, you can continue with the
tutorial.

Warren
Post by Canon
$ python setup.py build_ext --inplace
Then I get a syntax error on the dollar sign
What is going on? I get the same errors if I do steps 3-5 in the cmd.exe
Shell.
import pyximport; pyximport.install()
import helloworld
(I do this in IDLE)
and the result is a long list of errors.
What is going on???
Canon
2012-08-17 06:49:03 UTC
Permalink
I tried it, and it works. YES!!! lol. Thanks for highlighting those crucial
details, it was a big help.


If anyone is curious or ran into problems later on, here's 2 points that
may be helpful:

1) If you try to run your Cython program, and get an error that says:
Unable to find vcvarsall.bat

then you need to set minigw as the compiler, the following code should
work:

python setup.py build_ext --inplace --compiler=mingw32

2) The Cython tutorial I referenced earlier said you should see a .dll file
after the Cython program compiles in Windows. But chances are you will only
see a .pyd file in your directory, and no .dll file. That is fine, and the
.pyd file can serve as the .dll file. Just make sure the .pyd file is
accessible if your trying to import the cython program into IDLE or the
python interpreter. Otherwise you will get the error: no module named
whatever

#NoobProblems
Post by Canon
How do I run or compile Cython? So far I have been unable to do either.
Windows XP, 32-bit machine
downloaded Python (x,y) 2.7.2.3 (
http://code.google.com/p/pythonxy/wiki/Downloads)
I checked the boxes in the python package that would included Cython 0.16
and the MinGW compiler in the installation
I try to follow the steps in this Cython tutorial (
http://docs.cython.org/src/userguide/tutorial.html) but get errors. The
tutorial does not specify where these steps should be performed, maybe it
doesn't matter?
print "hello world"
2) I save this program as helloworld.pyx, and then close IDLE
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"])]
)
File "<pyshell#6>", line 3, in <module>
ext_modules = [Extension("helloworld",["helloworld.pyx"])]
File "C:\Python27\lib\distutils\core.py", line 140, in setup
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: --help [cmd1 cmd2 ...]
or: --help-commands
or: cmd --help
error: no commands supplied
from distutils.core import setupfrom distutils.extension import Extensionfrom Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("helloworld", ["helloworld.pyx"])])
and then, in a terminal (i.e. a DOS prompt, in the directory where
setup.py is saved), run the command
Post by Canon
python setup.py build_ext --inplace
Try that, and if you don't get any errors, you can continue with the
tutorial.
Warren
Post by Canon
$ python setup.py build_ext --inplace
Then I get a syntax error on the dollar sign
What is going on? I get the same errors if I do steps 3-5 in the cmd.exe
Shell.
import pyximport; pyximport.install()
import helloworld
(I do this in IDLE)
and the result is a long list of errors.
What is going on???
Warren Weckesser
2012-08-17 17:33:20 UTC
Permalink
Post by Canon
I tried it, and it works. YES!!! lol. Thanks for highlighting those
crucial details, it was a big help.
Great.

And thank *you* for following up with the additional details; those could
help the next person getting started with Cython in Windows.

Warren
Post by Canon
If anyone is curious or ran into problems later on, here's 2 points that
Unable to find vcvarsall.bat
then you need to set minigw as the compiler, the following code should
python setup.py build_ext --inplace --compiler=mingw32
2) The Cython tutorial I referenced earlier said you should see a .dll
file after the Cython program compiles in Windows. But chances are you will
only see a .pyd file in your directory, and no .dll file. That is fine, and
the .pyd file can serve as the .dll file. Just make sure the .pyd file is
accessible if your trying to import the cython program into IDLE or the
python interpreter. Otherwise you will get the error: no module named
whatever
#NoobProblems
Post by Canon
How do I run or compile Cython? So far I have been unable to do either.
Windows XP, 32-bit machine
downloaded Python (x,y) 2.7.2.3 (http://code.google.com/p/**
pythonxy/wiki/Downloads<http://code.google.com/p/pythonxy/wiki/Downloads>
)
I checked the boxes in the python package that would included Cython
0.16 and the MinGW compiler in the installation
I try to follow the steps in this Cython tutorial (
http://docs.cython.org/src/**userguide/tutorial.html<http://docs.cython.org/src/userguide/tutorial.html>)
but get errors. The tutorial does not specify where these steps should be
performed, maybe it doesn't matter?
print "hello world"
2) I save this program as helloworld.pyx, and then close IDLE
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"])]
)
File "<pyshell#6>", line 3, in <module>
ext_modules = [Extension("helloworld",["**helloworld.pyx"])]
File "C:\Python27\lib\distutils\**core.py", line 140, in setup
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: --help [cmd1 cmd2 ...]
or: --help-commands
or: cmd --help
error: no commands supplied
from distutils.core import setupfrom distutils.extension import Extensionfrom Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("helloworld", ["helloworld.pyx"])])
and then, in a terminal (i.e. a DOS prompt, in the directory where
setup.py is saved), run the command
Post by Canon
python setup.py build_ext --inplace
Try that, and if you don't get any errors, you can continue with the
tutorial.
Warren
Post by Canon
$ python setup.py build_ext --inplace
Then I get a syntax error on the dollar sign
What is going on? I get the same errors if I do steps 3-5 in the cmd.exe
Shell.
import pyximport; pyximport.install()
import helloworld
(I do this in IDLE)
and the result is a long list of errors.
What is going on???
Loading...