pyusb 2.7 windows install error

后端 未结 1 929
你的背包
你的背包 2020-12-22 12:31

I know similar things have been asked, but none of the solutions work for me/I get different errors. I am trying to install PyUSB on a 64-bit Windows 7 VM, with Python 2.7.<

相关标签:
1条回答
  • 2020-12-22 13:04

    If you haven't installed VS 2008, don't.

    If you have installed VS 2008 and can't get extensions to compile, I would uninstall VS 2008 and remove the directory for it under program files. The problem is likely to be that the express version doesn't ship with the 64-bit compilers.

    To get compiling extension files, install the Python 2.7 compilers for Windows from http://www.microsoft.com/en-gb/download/details.aspx?id=44266 The instructions say that setuptools 6.0 is needed but I couldn't get it to work even after updating.

    Once the compilers are installed, locate the directory containing vcvarsall.bat. For me it was

    C:\Users\MY_USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

    Open powershell there and run .\vcvarsall.bat amd64

    If you see this:

    PS C:\Users\MY_USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0> .\vcvarsall.bat amd64
    Setting environment for using Microsoft Visual Studio 2008 x64 tools.
    

    All is well.

    The next step is bizarre but essential and is explained at the end. Rename the directory 9.0 to VC.

    Add the environment variable VS90COMNTOOLS and set the value to be the path of your bin directory, which should now be: C:\Users\MY_USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\VC\VC\bin

    Now it should all work. Go and test it on an extension file:

    python setup.py build_ext --inplace
    

    Why the renaming of 9.0 to VC? Go to your python installation directory and find the distutils directory: python_base_dir\Lib\distutils

    Open up msvc9compiler.py in your text editor of choice and find line 247.

    productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
    

    This means that distutils will simply navigate to the environment var you added, go up two levels and then down into the VC file, hoping to find vcvarsall.bat.

    You can edit this file as an alternative to renaming 9.0 -> VC but I thought that was "dirtier".

    Also note the reason there needs to be no VS 2008 directory is line 242:

    if not productdir or not os.path.isdir(productdir):
    

    which ignores old registry entries for VS 2008 if the directory is removed.

    0 讨论(0)
提交回复
热议问题