Python 3.6 and Visual Studio 2017 32

As a new version of Visual Studio comes out, there are often fixes to put in your build chain tools so packages with external  C/C++ compilation requirements still work. For Python 3.6 and Visual Studio 2017 to work together, a good reference start point is the Windows compilers compatibility list on

Let’s try to compile scrapy which has a lot of dependencies including the twisted package.

Let’s assume you have installed “Visual Studio 2017 Community” on your PC with the C++ support. Trying to run the well-known

will end-up with a compile error, such as the following:

When working with Python 3.6 you may find however many stackoverflow articles stating that you must install Visual Studio 2015 back. Save yourself time and space by not doing it.

As mentioned as a requirement in the previously mentioned article, one requirement is to have a version of the setuptools library which is higher than 34.0. Unfortunately, Python 3.6 comes with 28.0 and the simple

won’t work as it tells you you have already what’s needed. Use instead:

If everything goes well, you’ll have:

This will allow Python to access your Visual Studio 2017 installation and no longer have two versions or more  installed in parallel.

The last trick is to use the proper environment to run command-line installations. With Visual Studio 2017 come multiple command prompts setups:

Do not choose ‘Developer’ although it may sound appealing. You’ll get caught with LNK2010  linking errors because of INCLUDE issues, in the same way that a regular cmd would output the  following error:

For proper compilation, choose the native architecture. In my case, I Choose ‘x64 Native Tools’ and finally got the following successful result:


Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

32 thoughts on “Python 3.6 and Visual Studio 2017

  • Ar one

    Thank you very much! Like a lot!!
    I couldn’t be bothered to download a humongous 4GB redundant older version c++ build tools, when I already have the latest ones.
    I tried searching for steps to make python choose the latest vs version for the build, but there were no relevant solutions. This one worked as a charm 🙂

  • Patrick

    Thank you very much for your solution. Worked perfectly! I did have to run the Command Prompt as administrator because I got an access denied error for read/write operations. Right mouse click Command Prompt as select: Run as administrator.

  • grateful dude

    Dimitri, man, thank you so much for the solution! 1 minute updating setuptools vs half a day downloading yet another version of MS monstrocity is quite a difference.

  • Dmitri

    Hello Dimitri. I failed to do the last trick. Can’t understand how could I run x64 Native Tools Command Prompt for VS 2017. I have only “Developer command prompt for VS 2017” available. Should I install something to have such a option?

    • Dimitri Post author

      Hello, in the version I installed, I’ve got 4 shortcut links under C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\VC
      The shortcut I’m talking about is running “%comspec% /k “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat”
      If you look into the that folder, do you have this vcvars64.bat? And is the Developer Command Prompt point to it?
      I’m wondering if the shortcut name changes with the Visual Studio releases or Edition…

      • Aayush Agrawal

        Even after trying the steps you mentioned, it’s giving the same error at my end. I also do not see the “Build” folder in the path below:
        C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
        which you have mentioned in the comment above!. What should I do in such a case.

        • Dimitri Post author

          In the Visual Studio Installer, under Individual Components, you may want to verify if ‘VC++ 2017 v141 toolset (x86,x64)’ is installed. Also do you have the Windows 10 SDK installed or not?

      • kapil

        Hello Dmitri
        I am trying to install cvxpy package which has many dependencies like scrapy using pip and got the errors you have mentioned above.
        So I have installed python -m pip install -U pip setuptools which is the first step and successfully done the step.
        coming to the second step how can I choose x64 Native Tools. I am confused.
        I have got 4 shortcut links in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\VC
        and I have got vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
        How to know Developer Command Prompt is pointing to it.

  • Jean

    Thanks a lot!
    However, after I did “python -m pip install -U pip setuptools” for my Python 3.6 and got “Successfully installed setuptools-38.5.1”, I still have this error:
    error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”:

    I am not sure my Path setting is correct though. I added to my Path the following:
    C:\Program Files (x86)\Microsoft Visual Studio\2017;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\MSBuild;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild;
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0

    Almost everything.

    Any clue?

    Thanks a lot!

    • Dimitri Post author

      As mentioned in one of my previous answers, the commands at the end are launched through the vcvars64.bat prompt, which among other things set the path, but also do a few other things. You may want to do your compilation from that command prompt to see if it is working there.

  • narayana

    hi after the step “python -m pip install -U pip setuptools” , i’m still getting a lot of errors.
    C:\Users\Narayana>pip install setuptools
    Requirement already satisfied: setuptools in c:\program files\python36\lib\site-packages

    C:\Users\Narayana>python -m pip install -U pip setuptools
    Requirement already up-to-date: pip in c:\program files\python36\lib\site-packages
    Collecting setuptools
    Using cached setuptools-38.5.2-py2.py3-none-any.whl
    Installing collected packages: setuptools
    Found existing installation: setuptools 28.8.0
    Uninstalling setuptools-28.8.0:
    Traceback (most recent call last):
    File “C:\Program Files\Python36\lib\”, line 544, in move
    os.rename(src, real_dst)
    PermissionError: [WinError 5] Access is denied: ‘c:\\program files\\python36\\lib\\site-packages\\__pycache__\\easy_install.cpython-36.pyc’ -> ‘C:\\Users\\Narayana\\AppData\\Local\\Temp\\pip-icydqxih-uninstall\\program files\\python36\\lib\\site-packages\\__pycache__\\easy_install.cpython-36.pyc’

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File “C:\Program Files\Python36\lib\site-packages\pip\”, line 215, in main
    status =, args)
    File “C:\Program Files\Python36\lib\site-packages\pip\commands\”, line 342, in run
    File “C:\Program Files\Python36\lib\site-packages\pip\req\”, line 778, in install
    File “C:\Program Files\Python36\lib\site-packages\pip\req\”, line 754, in uninstall
    File “C:\Program Files\Python36\lib\site-packages\pip\req\”, line 115, in remove
    renames(path, new_path)
    File “C:\Program Files\Python36\lib\site-packages\pip\utils\”, line 267, in renames
    shutil.move(old, new)
    File “C:\Program Files\Python36\lib\”, line 559, in move
    PermissionError: [WinError 5] Access is denied: ‘c:\\program files\\python36\\lib\\site-packages\\__pycache__\\easy_install.cpython-36.pyc’

    please help regarding this issue

    • Dimitri Post author

      Hello, Your error is permission denied as marked on the latest line. You may want to double check you have enough rights when executing those commands (local administrator in an elevated prompt)

      • narayana

        Hi, I opened Windows PowerShell as Admin. the command “python -m pip install -U pi setuptools” worked fine. it successfully updated the required ones. the 3rd part is not getting done. I opened x64 Native Tools as Admin but the commands are not going good. when i enter “pip install pyswisseph” i’m getting the error not able to link the visual studio.
        swhgeo.obj : error LNK2001: unresolved external symbol strtok_r
        build\\swisseph.cp36-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
        error: command ‘C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.13.26128\\bin\\HostX86\\x64\\link.exe’ failed with exit status 1120

        Command “”c:\program files\python36\python.exe” -u -c “import setuptools, tokenize;__file__=’C:\\Users\\Narayana\\AppData\\Local\\Temp\\pip-build-zxnmxm6a\\pyswisseph\\’;f=getattr(tokenize, ‘open’, open)(__file__);‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record C:\Users\Narayana\AppData\Local\Temp\pip-mi08v6hq-record\install-record.txt –single-version-externally-managed –compile” failed with error code 1 in C:\Users\Narayana\AppData\Local\Temp\pip-build-zxnmxm6a\pyswisseph\

        Basically i’m trying to workout the first command in the site :

        • Dimitri Post author

          Your issue has nothing to do with the Python support anymore. You’re trying to compile C Code for which there’s a call to a function ‘strtrok_r’. strtok_r is not supported on the Windows platform. I would look into the source code of the package or contact the author to know which symbol should be defined to compile under Windows eventually: there’s probably a #define Win32 missing…

          • narayana

            Hi, Thanks for the info. I contacted the author. He said it was done for Linux and he doesn’t know how to do it on Windows. I think maybe that is the problem. Thanks for the support.

  • stpaulchuck

    OMG! thanks ever so much!! I never knew those launch icons were in there. I tried all the other approaches to no avail. Launching the X64 native as administrator and pip install line_profiler went PERFECT.

    I love the interwebs. You always run into smart people out here that figured something out.

    Cheers guys!

    • Dimitri Post author

      I’ve haven’t attempted this one, but which kind of error messages do you get? At Compilation? At Linking?

  • Tim Buchholz

    I am trying to install pyyawt (python 3.6.5 visual studio 2017) and it keeps raising this error:
    Command “”C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe” -u -c “import setuptools, tokenize;__file__=’C:\\Users\\TIMBUC~1\\AppData\\Local\\Temp\\pip-install-qwvadbd5\\pyyawt\\’;f=getattr(tokenize, ‘open’, open)(__file__);‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record C:\Users\TIMBUC~1\AppData\Local\Temp\pip-record-iksuld9r\install-record.txt –single-version-externally-managed –compile” failed with error code 1 in C:\Users\TIMBUC~1\AppData\Local\Temp\pip-install-qwvadbd5\pyyawt\
    Do you have any idea how I could fix this?

    • Dimitri Post author

      I didn’t try to compile PyYAWT myself but from the trace, I wouldn’t say it is an issue with the python path. In the documentation of the project, under ‘developmnt notes’, compiling under Windows seem to require to set some environment variables. Did you do it?

    • Dimitri

      You do not indicate if you use the proper command prompt to compile the extension. Updating setuptools alone does not suffice.

  • Ruslan

    Hi Dimitri!
    I have installed setuptools, but anyway I have error: command ‘C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x64\\cl.exe’ failed with exit status 2

    • Dimitri Post author

      Error code 2 means file not found. Updating python’s setuptools does the python part to avoid the concurrent installation of several Visual Studio versions. However you must still install the Visual Studio 2017 C++ buid tools to get cl.exe.