我刚刚下载了Enthown的Canopy学术版,安装了Cython和MinGW(以及许多其他软件包),并想通过cell magic%%Cython在ipython笔记本上使用一些Cython代码,这是我之前写的。我也在使用Windows764位。
除了我得到这个:
DistutilsPlatformError: Could not find Visual Studio 2008 in your path.
If you do not have Visual Studio 2008 installed, you can use
the MinGW compiler instead. To install mingw, do:
enpkg mingw
To use the MinGW compiler to build an extension module, use
the '-c' flag, e.g.:
python setup.py build_ext -c mingw64
Note that building Python extensions with MinGW is not officially
supported, although it is known to work in many cases.
这是在Cython文档中提到的,如果mingw没有添加到PATH中,就会发生这种情况。我觉得这对水蟒来说容易多了,但我到目前为止所做的是:
我试着把这些添加到我的路径中:
C:\Users\Patrick\User\EGG-INFO\mingw\usr\x86_64-w64-mingw32\bin
C:\Users\Patrick\User\EGG-INFO\mingw\usr\bin
C:\Users\Patrick\User\Lib\site-packages\mingw-4.8.1-2.egg-info\scripts
我该怎么做才能让Cython和EPD一起使用mingw?
最佳答案
我用的是学术版的《热情的冠层》,我和你有同样的问题。
我通过将系统环境变量中的VS90COMNTOOLS
设置为C:/program files (x86)/Microsoft Visual Studio 12.0/Common7/Tools
解决了这个问题(我在windows 8.1 x64中使用VS2013 Pro)
我还添加了vcvarsall.bat
的路径,在我的例子中是:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
到系统环境变量
在命令提示符下运行vcvarsall.bat
,然后运行python setup.py build_ext --inplace
,它应该可以工作
编辑:
我已经用这个测试过了,并且工作过:
In [1] : %load_ext cythonmagic
In [2] : %%cython
def fib(int n):
cdef int i, a, b
a, b = 1, 1
for i in range(n):
a, b = a+b, a
return a
In [3] : fib(10)
Out[3] : 144