Rich Signell
Rich Signell

Reputation: 16375

Can I use the free Microsoft C++ Compiler for Python 2.7 to build conda packages?

Is it possible to build binary conda python packages using the free Microsoft C++ Compiler for Python 2.7?

I installed the compiler on my Windows 7 machine, but when I try a conda build (e.g. conda build pyproj from https://github.com/ioos/conda-recipes/tree/master/pyproj), I get:

C:\Anaconda64\conda-bld\work\pyproj-1.9.3>set USERPROFILE=C:\Users\rsignell

C:\Anaconda64\conda-bld\work\pyproj-1.9.3>REM ===== end generated header =====
C:\Anaconda64\conda-bld\work\pyproj-1.9.3>"C:\Anaconda64\envs\_build\python.exe"
 setup.py install
Traceback (most recent call last):
  File "setup.py", line 14, in <module>
    objects = cc.compile(['nad2bin.c', 'src/pj_malloc.c'])
  File "C:\Anaconda64\envs\_build\lib\distutils\msvc9compiler.py", line 473, in
compile
    self.initialize()
  File "C:\Anaconda64\envs\_build\lib\distutils\msvc9compiler.py", line 383, in
initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:\Anaconda64\envs\_build\lib\distutils\msvc9compiler.py", line 271, in
query_vcvarsall
    raise DistutilsPlatformError("Unable to find vcvarsall.bat")
distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat

C:\Anaconda64\conda-bld\work\pyproj-1.9.3>if errorlevel 1 exit 1
Command failed: C:\Windows\system32\cmd.exe /c bld.bat

My conda info is:

c:\Users\rsignell\Documents\GitHub\conda-recipes>conda info
Current conda install:

             platform : win-64
        conda version : 3.8.1
  conda-build version : 1.10.0
       python version : 2.7.8.final.0
     requests version : 2.5.1
     root environment : C:\Anaconda64  (writable)
  default environment : C:\Anaconda64
     envs directories : C:\Anaconda64\envs
        package cache : C:\Anaconda64\pkgs
         channel URLs : http://repo.continuum.io/pkgs/free/win-64/
                        http://repo.continuum.io/pkgs/pro/win-64/
          config file : None
    is foreign system : False

Upvotes: 3

Views: 5715

Answers (1)

Joost Janse
Joost Janse

Reputation: 31

I had the same problem and solved it with a patch like this:

  1. set an environment variable (be sure to use your own name):

    VS90COMNTOOLS=C:\Users\joost\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

  2. patch the file C:\Users\joost\Anaconda\Lib\distutils\msvc9compiler.py

        if not os.path.isdir(productdir):
            log.debug("%s is not a valid directory" % productdir)
            return None
    

    into:

    if not os.path.isdir(productdir):
        productdir = toolsdir
        if not os.path.isdir(productdir):
            log.debug("%s is not a valid directory" % productdir)
            return None  
    

Done! The bug is that the vcvarsall.bat file was searched at ..\..\VC dir that isn't there in the Microsoft Visual C++ Compiler for Python 27.

Upvotes: 3

Related Questions