Wednesday, February 19, 2014

How to fix "ValueError when trying to compile python module with VC Express"

When I tried to compile the python, I always get compile issue as following:
------------
...
  File "C:\Python26\lib\distutils\msvc9compiler.py", line 358, in 
initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:\Python26\lib\distutils\msvc9compiler.py", line 274, in 
query_vcvarsall
    raise ValueError(str(list(result.keys())))
ValueError: [u'path']
---------------------
Python community discussed a lot but no solution: http://bugs.python.org/issue7511

The root cause is because the latest visual studio change the *.bat file a lot especially on 64bit env. The python 2.7 didn't update the path accordingly. 
Based on the assumption above, the following solution worked for me.
To install Visual Studio 2008 Express Edition with all required components:
1. Install Microsoft Visual Studio 2008 Express Edition. The main Visual Studio 2008 Express installer is available from (the C++ installer name is vcsetup.exe):
This package can be installed using the default options.
2. Install the Microsoft Windows SDK. The Microsoft Windows SDK is available by searching Microsoft's download site, or by going directly to:
Download the Windows Server 2008 & .NET 3.5 SDK. Do not install beta or 'Release Candidate' (RC) versions. Also do NOT install "Microsoft Windows SDK for Windows 7 and .NET Framework 4" (version 7.1); if you want to use a 7.x version choose the "Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1".
2.1. While installing the SDK, you must select "x64 Compilers and Tools". For example, in the SDK installer above:
On the screen "Installation Options"
Select "Developer Tools"->"Visual C++ Compilers".
This item has the Feature Description "Install the Visual C++ 9.0 Compilers. These compilers allow you to target x86, x64, IA64 processor architectures."
3. To verify that you have all installed components, check that the Microsoft SDK contains the "amd64" version of the C/C++ compiler "cl.exe". This is usually installed into
 C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\cl.exe
4. copy .../VC/bin/vcvars64.bat to .../VC/bin/vcvarsamd64.bat
5. copy .../VC/bin/vcvars64.bat to .../VC/bin/amd64/vcvarsamd64.bat

Now, get the coffee and wait for the compile result:)

21 comments:

  1. Hey there, I am having the same issue, but I have Visual Studio 2010 and .NET 4 SDK installed on my computer. I just did not quite understand why I had to install 2008 version and SDK 3.5?
    Thanks

    ReplyDelete
    Replies
    1. the latest 2010 removed some bat files which are required to compile python module.

      Delete
  2. In the last two steps:
    4. copy .../VC/bin/vcvars64.bat to .../VC/bin/vcvarsamd64.bat

    5. copy .../VC/bin/vcvars64.bat to .../VC/bin/amd64/vcvarsamd64.bat

    are we supposed to copy the file vcvars64.bat to folder amd64 and rename it as vcvarsamd64.bat?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. First of all thanks for putting up these helpful instructions.

    I am using a windows 8.1, python 3.4 amd64 bit computer with visual C++ express 2008 and 10 installed on the system.

    I followed your instructions but I am still getting the ValueError when trying to install my module. should we also have vcvars64.bat file in the amd64 folder as well.

    And for the 2.1 Step I do not see the installation options you speak of.

    ReplyDelete
    Replies
    1. I feel painful that we can't see the installation options for 2.1 step. are u using 32 bit pc or 64 bits?

      Delete
    2. Got the same problem
      I use 64 bit and tried everything nothing seems to working. I use vs 2013 and python 3.4 (I want to use mmh3). get still a path error because there is no such a path \Bin\SetEnv.cmd in "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd under windows 8 :/

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. I have just one thing to say you: Thank you so much! :D

    ReplyDelete
  7. I've searched far and wide for an answer to this problem, and this was the one. You are a god among mere mortals.

    ReplyDelete
  8. Hiện nay, nhiều nhà doanh nghiệp đang phải tốn rất nhiều chi phí khi nhập khẩu hàng hóa từ nhật bản vì các thủ tục hải quan. Tuy nhiên, khi dịch vụ của chúng tôi ra đời đã có thể giải quyết được những vấn đề khó khăn này. Chúng tôi nhận mua hộ hàng nhật tại các trang web nổi tiếng của Nhật Bảm mua hàng trên web nhật. Hơn nữa, chúng tôi còn phát triển mạnh dịch vụ chuyển đồ từ nhật về việt nam. Chuyển hàng ở các tỉnh thành lớn như hà nội, hồ chí minh, đã nẵng mới mức phi cực rẻ. nhận chuyển hàng từ nhật về hà nội hoặc nhận chuyển hàng từ nhật về tphcm . Quý khách chỉ cần order hàng từ nhật về việt nam và sử dụng dịch vụ order hàng nhật để nhận được những sự hài lòng nhất từ dịch vụ ordershiphangnhat.com của chúng tôi.

    Ngoài ra, chúng tôi còn cung cấp thêm dịch vụ mua hàng trên amazon ship về việt nam, quý khách hàng có thể mua sắm tưng bừng tại hệ thông amazon

    ReplyDelete
  9. http://www.lfd.uci.edu/~gohlke/pythonlibs/#vlfd
    Please refer this site to download binary compile libraries for any python module and after downloading .whl file install like
    pip -m install

    ReplyDelete
  10. Zheng! You are the man!!! This is pure gold!

    Thank you for having the patience to figure this out, and the compassion to write it up so clearly for the rest of us!!!

    ReplyDelete
  11. Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!
    Commercial Audio Visual Design & Commercial AV System integration & Commercial AV installation Southbay

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Even after following the above procedure,I am getting the following errors.Please help if possible.
    cl : Command line error D8021 : invalid numeric argument '/Wno-cpp'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2

    ReplyDelete