How to install cython an Anaconda 64 bits with Windows 10?

 ̄綄美尐妖づ 提交于 2020-12-03 07:35:48

问题


It's all in the title, does someone have a step by step method to install cython and run it on Anaconda 64 bits on Windows 10? I search for hours and there are a lot of tutorials... For things that I wasn't able to get or do on windows 10. I try to follow all those methods and more but in vain for now: https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_Cython_On_Anaconda_On_Windows?lang=en

https://github.com/cython/cython/wiki/CythonExtensionsOnWindows

Conda install is done but the problem is to link the compiler to python, all the method using windows SDK and espescially the SDK command prompt are outdated, this prompt doesn't exist on Visual studio 2015 and the setenv function doesn't exist anymore either so impossible to execute 'setenv \x64 \release' and without this step the code doesn't work.

The other methode with MinGW return an error:

C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-3.6\Release\hello.o build\temp.win-amd64-3.6\Release\hello.cp36-win_amd64.def -LC:\Users\Utilisateur\Anaconda3\libs -LC:\Users\Utilisateur\Anaconda3\PCbuild\amd64 -lpython36 -lmsvcr140 -o C:\Users\Utilisateur\Documents\hello.cp36-win_amd64.pyd
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lmsvcr140
collect2.exe: erreur : ld a retourné 1 code d'état d'exécution
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1

so I don't know what to do next.

Help please.

A desperate student


回答1:


Ok I solved the problem on Windows 10 with Anaconda using python 3.6.5 and MSC v.1900 64 bit (informations given by running :

import sys
sys.version

so here is the method:

1: install cython by running conda install -c anaconda cython in Anaconda prompt

2: go in C:\Users\Utilisateur\Anaconda3\Lib\distutils or wherever your distutils library is the create a distutils.cfg file (by using the notepad) and put

[build]           
compiler=mingw32 

in it

3: get the latest version of Mingw-w64 (not just Mingw which support just 32 bits) at https://sourceforge.net/projects/mingw-w64/files/ and install it

4: add C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin to your Path here is a link on how to do that on windows 10: https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

5: install libpython and m2w64-toolchain in your anaconda envirement by running conda install -c anaconda libpython and conda install -c msys2 m2w64-toolchain It come from these webpage https://python-at-risoe.pages.windenergy.dtu.dk/compiling-on-windows/common_errors.html and should correct the corresponding errors

6: try the first or second test on this page http://docs.cython.org/en/latest/src/quickstart/build.html both were working for me after step 5

Hope it will help!




回答2:


Are you sure that using MinGW-w64 is ok? In the Cython Wiki, they say that it is not recommended:

** Do not use MinGW-w64. As you will notice, the MinGW import library for Python (e.g. libpython27.a) is omitted from the AMD64 version of Python. This is deliberate. Do not try to make one using dlltool. There is no official MinGW-w64 release yet, it is still in "beta" and considered unstable, although you can get a 64-bit build from e.g. TDM-GCC. There have also been issues with the mingw runtime conflicting with the MSVC runtime; this can happen from places you don't expect, such as inside runtime libraries for g++ or gfortran. To stay on the safe side, avoid MinGW-w64 for now.

** Those with experience from Linux or Apple MacOSX might pick GCC (MinGW) as their C/C++ compiler of choice on Windows. Note that GCC is not the platform C compiler on Windows. To be binary compatible with most libraries and applications on Windows, use Microsoft's compiler. This is no different from selecting GCC as the compiler of choice on Linux. Microsoft's platform C/C++ compiler for Windows is free of charge.

** For C++, observe that GCC (Mingw) and MSVC use different C++ runtimes. If you use C++ in your extension, the C++ runtime must also be compatible with Python's C runtime. For this reason, always use Microsoft's compiler for C++, even on 32-bit x86. This is very important on a platform like Windows where C++ is pervasive (cf. COM and ActiveX). If you use GCC as C++ compiler your extension will not be binary compatible with other C++ libraries or COM, not be compatible with Python's C runtime, and differences in exception handling between GCC and MSVC can crash your application.




回答3:


Although not the answer for windows 10, but windows 7. I would like to tell how I did it.

  1. I started with Anaconda (using : Anaconda 2019.10 for Windows Installer - Python 3.7 version 64 bit)). It is build with the Microsoft compiler not with MinGW (in python sys.version reports: MSC v.1915 64 bit (AMD64). Anaconda comes with Cython installed, but not with the MSC compiler. So trying the cython example in Jupyter:
    %load_ext Cython

    %%cython
    cdef int a = 0
    for i in range(10):
        a += i
    print(a)

This now throws an error : Unable to find vcvarsall.bat

  1. Cython with Python 3.7 needs Visual C++ 2015 (14.0). I couldn't download this version anymore from microsoft so I downloaded visual studio installer: Visual Build Tools 2019. In the installer I selected in "workloads" the C++ build tools. Then on the right hand side

I UNselected:

  • MSVC v142 - VS 2019 C++ x64/x86 build tools
  • C++ CMake tools for windows
  • C++ AddressSanititizer (experimental)

I selected:

  • Windows 10 SDK
  • Testing tools core features - Build Tools
  • C++/CLI support for v142 build tools
  • MSVC V140 - VS 2015 C++ build tools

After installing this and running the above example again I ran into a linker error: LINK : fatal error LNK1158

3) In some subdirectory of directory C:\Program files (x86)\Windows Kits I found the files: rc.exe and rcdll.dll
I copied those to the bin directory of MSVC in my case: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin

This made the linker error disappear and the cython example work! I haven't tried anything else yet, but I do hope this is all that needs to be done. Hope this helps someone.



来源:https://stackoverflow.com/questions/52864588/how-to-install-cython-an-anaconda-64-bits-with-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!