2014-06-21 57 views
3

我剛剛下載了Enthought的Canopy學術版本,並安裝了Cython和MinGW(以及很多其他軟件包),並希望在ipython筆記本中通過單元魔術使用一些cython代碼%我以前寫過的%cython。此外,我正在使用Windows 7 64位。如何讓cython使用MinGW與enthought冠層分佈

除非我得到這個:

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使用的MinGW環保署?

+0

也試過這個'C:\用戶\ Patrick \ User \ Lib \ site-packages \ mingw-4.8.1-2.egg \ EGG-INFO \ usr \ bin'這應該是正確的位置。我以前在Anaconda爲了使mingw工作,我還記得在''build''下設置'compiler = mingw32',在'disutils.cfg'中設置'[build_ext]',但是這個文件在EPD中找不到。任何人都可以告訴我在哪裏可以找到這個文件,所以我可以試試嗎? – pbreach

+0

嘗試過'%% cython -c = mingw32'和'%% cython -compiler = mingw'沒有成功。安裝了Visual Studio 2008速成版,它給出了同樣的錯誤,並附加一條說明,完整版本是64位系統所需的,而不是快速版本。這成爲一個真正的痛苦。 – pbreach

+0

[我使用Canopy組合MinGW沒有問題,請參考我對此問題的回答。](http://stackoverflow.com/a/36511007/5853731) –

回答

1

好了,到目前爲止,我的解決方案是完全卸載EPD和蟒蛇,然後重新安裝蟒蛇和一切再次工作。起初我以爲這是因爲Anaconda和EPD在一起玩的不好。但我也嘗試再次卸載Anaconda,然後安裝EPD,仍然得到相同的錯誤。我確認安裝了mingw,這次安裝EPD時它會自動附加到我的路徑中。

如果你想嘗試重建這個錯誤嘗試在Windows 7上安裝EPD canopy-1.4.0-win-64 64位,並嘗試使用例如%%cython細胞魔法IPython的筆記本電腦創建一個簡單的用Cython功能:

%load_ext cythonmagic 

In [18]: 

%%cython 
cimport cython 
cpdef f(int x): 
    cdef int y = x+2*100 
    return y 

--------------------------------------------------------------------------- 
DistutilsPlatformError     Traceback (most recent call last) 
<ipython-input-18-326d9aaeb05c> in <module>() 
----> 1 get_ipython().run_cell_magic(u'cython', u'', u'cimport cython\ncpdef f(int x):\n cdef int y = x+2*100\n return y') 

C:\Users\Patrick\User\lib\site-packages\IPython\core\interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell) 
    2160    magic_arg_s = self.var_expand(line, stack_depth) 
    2161    with self.builtin_trap: 
-> 2162     result = fn(magic_arg_s, cell) 
    2163    return result 
    2164 

C:\Users\Patrick\User\lib\site-packages\IPython\extensions\cythonmagic.pyc in cython(self, line, cell) 

C:\Users\Patrick\User\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k) 
    191  # but it's overkill for just that one bit of state. 
    192  def magic_deco(arg): 
--> 193   call = lambda f, *a, **k: f(*a, **k) 
    194 
    195   if callable(arg): 

C:\Users\Patrick\User\lib\site-packages\IPython\extensions\cythonmagic.pyc in cython(self, line, cell) 
    266    build_extension.build_temp = os.path.dirname(pyx_file) 
    267    build_extension.build_lib = lib_dir 
--> 268    build_extension.run() 
    269    self._code_cache[key] = module_name 
    270 

C:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\distutils\command\build_ext.py in run(self) 
    335 
    336   # Now actually compile and link everything. 
--> 337   self.build_extensions() 
    338 
    339  def check_extensions_list(self, extensions): 

C:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\distutils\command\build_ext.py in build_extensions(self) 
    444 
    445   for ext in self.extensions: 
--> 446    self.build_extension(ext) 
    447 
    448  def build_extension(self, ext): 

C:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\distutils\command\build_ext.py in build_extension(self, ext) 
    494           debug=self.debug, 
    495           extra_postargs=extra_args, 
--> 496           depends=ext.depends) 
    497 
    498   # XXX -- this is a Vile HACK! 

C:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\distutils\msvc9compiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends) 
    512 
    513   if not self.initialized: 
--> 514    self.initialize() 
    515   compile_info = self._setup_compile(output_dir, macros, include_dirs, 
    516           sources, depends, extra_postargs) 

C:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\distutils\msvc9compiler.py in initialize(self, plat_name) 
    422        PLAT_TO_VCVARS[plat_name] 
    423 
--> 424    vc_env = query_vcvarsall(VERSION, plat_spec) 
    425 
    426    # take care to only use strings in the environment. 

C:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\lib\distutils\msvc9compiler.py in query_vcvarsall(version, arch) 
    304  if vs_info is None: 
    305   raise DistutilsPlatformError(
--> 306    '\n'.join((VS_NOT_FOUND_MESSAGE, MINGW_DEFLECT_MESSAGE))) 
    307 
    308  vcvarsall, is_express = vs_info 

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. 

我以前也加入到distutils.cfgC:\Users\Patrick\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.0.1938.win-x86_64\Lib\distutils如下:

[build] 
compiler = mingw32 

[build_ext] 
compiler = mingw32 

但還是同樣的問題。有沒有人能夠在ipython中使用%%cython作爲所提到的平臺而沒有完整版本的VS 2008?

0

根據https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows並結合我自己的經驗,MinGW,64位和Cython的組合不起作用。 (也有利於本http://www.mathworks.com/matlabcentral/answers/98351-how-can-i-set-up-microsoft-visual-studio-2008-express-edition-for-use-with-matlab-7-7-r2008b-on-64

你問是否需要VS2008的完整版本。我的理解是,Visual Studio Express版本和64位SDK(鏈接中的參考)的組合應該足夠了。 VS2008可從https://www.dreamspark.com/Product/Product.aspx?productid=34和SDK這裏獲得http://www.microsoft.com/en-us/download/details.aspx?id=24826。請記住在安裝SDK時選擇64位編譯器。

+0

自從我回到Anaconda後,我一直在能夠在ipython筆記本中使用cython並使用disutils構建cython模塊。必須是EPD的某種配置問題(Anaconda也使用MinGW)。 – pbreach

2

我使用enthought篷的學術版本和我有同樣的問題,因爲你。

我通過在系統環境變量中設置VS90COMNTOOLSC:/program files (x86)/Microsoft Visual Studio 12.0/Common7/Tools(我在Windows 8中使用VS2013 Pro來解決此問題。1 x64)的

我還增加了路徑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 
+0

太棒了!我必須在週末的某個時候嘗試一下。我一直在使用Anaconda,但EPD看起來相當不錯,尤其是對於安裝有很多依賴的軟件包。我也在使用學術版,所以我希望它能奏效 – pbreach