Skip to main content

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:)

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. fantastic post.. it works for me !

    ReplyDelete
  3. 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
  4. This comment has been removed by the author.

    ReplyDelete
  5. 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
  6. This comment has been removed by the author.

    ReplyDelete
  7. You saved my life !!! ...thanks

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

    ReplyDelete
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. This comment has been removed by the author.

    ReplyDelete
  15. 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

Post a Comment

Popular posts from this blog

How to convert the ResultSet to Stream

Java 8 provided the Stream family and easy operation of it. The way of pipeline usage made the code clear and smart. However, ResultSet is still go with very legacy way to process. Per actual ResultSet usage, it is really helpful if converted as Stream. Here is the simple usage of above: StreamUtils.uncheckedConsumer is required to convert the the SQLException to runtimeException to make the Lamda clear.

How to run odoo(openerp8) in IDE from source on windows

1. install python 2.7 (per openerp8's official doc, python 27 is required.) 2. download get-pip.py from https://bootstrap.pypa.io/get-pip.py , execute the command: python get-pip.py 3. get source of openerp8 from https://github.com/odoo/odoo.git 4. execute the command: pip install -r D:\source_code\odoo\openerp8/requirements.txt . (requirements.txt contains all dependencies. ) The pip will install the python module automatically. However, the real world always bring us the issues because our C++ compile environment is not setup correctly.  we will get the link error when pip try to install psycopg2 (driver to access postgresql db.). Go to  http://www.stickpeople.com/projects/python/win-psycopg/  and choose the compiled binary file directly. For Python-ldap, go to  http://www.lfd.uci.edu/~gohlke/pythonlibs/ 5. Finally, go to http://sourceforge.net/projects/pywin32/files/pywin32 and choose correct version for python-win32service. 6. If you are family with eclipse a lot,