Search code examples
pythonmoduleinstallationraspberry-pigpio

How to install RPi.GPIO to windows


I have looked and most of the tutorials are rasbian based. I would like it on windows so I can develop a python script on windows to which would later be put on the Raspberry pi.

I have downloaded the module and have tried python setup.py install in command prompt as administrator and receive the following error.

error: Unable to find vcvarsall.bat

I looked this up and the solutions suggested haven't helped. A solution would be appreciated!


Solution

  • First you should look for the file vcvarsall.bat in your system.

    If it does not exits I recommend you to install Microsoft Visual C++ Compiler for Python 2.7. This will create the vcvarsall.bat in "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0" if you install it for all users.

    The problem now is that a function find_vcvarsall(version) in the C:/Python27/Lib/distutils/msvc9compiler.py module is the one looking for vcvarsall.bat.

    If you follow the function calls you will see is looking in the registry for the directory of the vcvarsall.bat file and it won't never find it because the function is looking in other directories different from where the above mentioned installation placed it, and in my case the registry didn't exits.

    The easiest way to solve this problem is to remove the body (or just place in the first line) of the function find_vcvarsall(version) in the msvc9compiler.py file with the absolute path to vcvarsall.bat. For example:

    def find_vcvarsall(version):
    return r"C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"
    

    If you already have the vcvarsall.bat file you should check if you have the key productdir in the registry:

    (HKEY_USERS, HKEY_CURRENT_USERS, HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT)\Software\Wow6432Node\Microsoft\VisualStudio\version\Setup\VC

    If you don't have the key just do:

    def find_vcvarsall(version):
        return <path>\vcvarsall.bat
    

    To understand the exact behavior check msvc9compiler.py module starting in the find_vcvarsall(version) function.

    This worked for me. for more visit this post pip install gives error: Unable to find vcvarsall.bat