mckib2 / pygrappa

Python implementations of GRAPPA-like algorithms.

Home Page:https://pygrappa.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows installation

mckib2 opened this issue · comments

Windows 10, python 3.7.3, pygrappa v0.4.0.

In clean virtual environment
command: pip install pygrappa

Output:

...
building 'pygrappa.cgrappa' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

Looks like official documentation suggests "Microsoft Visual C++ Build Tools" is the correct answer, but I'm going to try with MinGW to see if it'll work

The computer I had access to that had Windows 10 did not give me admin rights. So all steps below assume no admin rights (part of the reason I couldn't go with VS C++ 14.0 option, requires admin rights to install...)

First try...

  • Download Python 3.7.3 64-bit
  • Download official MinGW, only comes in 32-bit flavor
  • Add to PATH
  • Find vcruntime140.dll online, download it and put in pythonpath/libs
  • Modify cygwinccompiler.py according to tgalal/yowsup#2494 :

@cesardmoro
edit your cygwinccompiler.py and download vcruntime140.dll and paste into pythonpath/libs

def get_msvcr():
    """Include the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    """
    msc_pos = sys.version.find('MSC v.')
    if msc_pos != -1:
        msc_ver = sys.version[msc_pos+6:msc_pos+10]
        if msc_ver == '1300':
            # MSVC 7.0
            return ['msvcr70']
        elif msc_ver == '1310':
            # MSVC 7.1
            return ['msvcr71']
        elif msc_ver == '1400':
            # VS2005 / MSVC 8.0
            return ['msvcr80']
        elif msc_ver == '1500':
            # VS2008 / MSVC 9.0
            return ['msvcr90']
        elif msc_ver == '1600':
            # VS2010 / MSVC 10.0
            return ['msvcr100']
        elif msc_ver == '1700':
            # Visual Studio 2012 / Visual C++ 11.0
            return ['msvcr110']
        elif msc_ver == '1800':
            # Visual Studio 2013 / Visual C++ 12.0
            return ['msvcr120']
        elif msc_ver == '1900':
            # Visual Studio 2015 / Visual C++ 14.0
            # "msvcr140.dll no longer exists" http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx
           return ['vcruntime140']    
        else:
            raise ValueError("Unknown MS Compiler version %s " % msc_ver)
  • run pip install --global-option build_ext --global-option --compiler=mingw32 pygrappa (see pypa/pip#18 (comment))

Unfortunately this leads to an error stemming from a mismatch between MinGW and Python, 32 bit and 64 bit respectively (see kivy/cymunk#52 (comment)).

Let's try again, this time with 64 bit MinGW...

  • Download MinGW (choose 32 or 64, whichever corresponds to the python build you have. I'm using python 3.7.3 , so get 64 bit following this guide: https://github.com/orlp/dev-on-windows/wiki/Installing-GCC--&-MSYS2)
  • Install everything in previously mentioned guide and add everything to PATH. I had to edit PATH for current user because I didn't have admin rights. I'll reproduce the relevant parts from the guide here in case the link ever goes bad:

If you have a 32-bit development machine, change every occurrence of C:\dev\msys64 with C:\dev\msys32 below. However, it's <current year>, get a 64-bit machine.

Download msys2-x86_64-latest.exe and run it. If your development machine is 32-bit, download msys2-i686-latest.exe instead. Make sure to set the install directory to C:\dev\msys64 (C:\dev\msys32 for 32-bit). Choose to run MSYS2 right now.

In the MSYS2 shell, execute the following. Hint: if you right click the title bar, go to Options -> Keys and tick "Ctrl+Shift+letter shortcuts" you can use Ctrl+Shift+V to paste in the MSYS shell.

pacman -Syuu
Close the MSYS2 shell once you're asked to. There are now 3 MSYS subsystems installed: MSYS2, MinGW32 and MinGW64. They can respectively be launched from C:\dev\msys64\msys2.exe, C:\dev\msys64\mingw32.exe and C:\dev\msys64\mingw64.exe. If the installer created any shortcuts to open shells for these subsystems, you can update them to these locations to get pretty icons. Each subsystem provides an environment to build Windows applications. The MSYS2 environment is for building POSIX compliant software on Windows using an emulation layer. The MinGW32/64 subsystems are for building native Windows applications using a linux toolchain (gcc, bash, etc), targetting respectively 32 and 64 bit Windows. We will install our PATH such that these tools can be called from regular cmd.exe as well, and we need only use the MinGW subsystem to install/update MSYS2 packages or if our build setup requires a *nix shell. Hint: after starting up MSYS2, the prompt will say which version you launched.

Reopen MSYS2 (doesn't matter which version, since we're merely installing packages). Repeatedly run the following command until it says there are no further updates. You might have to restart your shell again.

pacman -Syuu
Now that MSYS2 is fully up-to-date we will install GCC and common build tools. When you are queried to select packages and confirm the installation just press enter:

pacman -S --needed base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain
git subversion mercurial
mingw-w64-i686-cmake mingw-w64-x86_64-cmake
Add C:\dev\msys64\mingw64\bin and C:\dev\msys64\mingw32\bin, in that order, to your PATH. Note that MSYS2 also puts a lot of other tools in this directory, most notably Python. So put these entries below any other tools you might have installed in your PATH.

  • Again, modify cygwinccompiler.py similar to tgalal/yowsup#2494 (it doesn't seem like we need vcruntime140.dll this time), but using the version number 1916:
def get_msvcr():
    """Include the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    """
    msc_pos = sys.version.find('MSC v.')
    if msc_pos != -1:
        msc_ver = sys.version[msc_pos+6:msc_pos+10]
        if msc_ver == '1300':
            # MSVC 7.0
            return ['msvcr70']
        elif msc_ver == '1310':
            # MSVC 7.1
            return ['msvcr71']
        elif msc_ver == '1400':
            # VS2005 / MSVC 8.0
            return ['msvcr80']
        elif msc_ver == '1500':
            # VS2008 / MSVC 9.0
            return ['msvcr90']
        elif msc_ver == '1600':
            # VS2010 / MSVC 10.0
            return ['msvcr100']
        elif msc_ver == '1916':
            # Visual Studio 2015 / Visual C++ 14.0
            # "msvcr140.dll no longer exists" http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx
            return ['vcruntime140']    
        else:
            raise ValueError("Unknown MS Compiler version %s " % msc_ver)
  • now run the command pip install --global-option build_ext --global-option --compiler=mingw32 --global-option -DMS_WIN64 pygrappa.

We need to explicitly give option -DMS_WIN64 as in cython/cython#2670 (comment):

@gui36 I have a similar issue with my code and had a discussion in the cython-users Google group. The problem is in the header pyport.h, in which SIZEOF_VOID_P is defined based on whether MS_WIN64 is defined or not. The solution is to pass -DMS_WIN64 when compiling with MinGW.

Summary:

  • Use Python 3.7 64-bit
  • Use 64-bit MinGW fork
  • Change cygwinccompiler.py to not break with non-visual-studio compilers
  • Pass compilation options explicitly when installing using pip

Running basic_cgrappa.py needs scipy.