Wednesday, May 31, 2017

Windows Python 3.6, VS2017 and the case of the missing basetsd.h

So you decided to join the Python 3 bandwagon on Windows with your new shiny Visual Studio. And then you start work on a fresh virtual environment and then you do a pip install or something. Sometimes, you'll end up with a compile error just like this:
WTF is this missing 'basetsd.h' file
You'll google this and end up with one of many stackoverflow topics stating you must install Visual Studio 2015 or some SDK.

Fuck that and save your time. You can do better because a programmer named Dimitri Janczak found a solution that works and I can confirm it works. 

The solution is as follows:

1. Install or update setuptools (> 34.0). Do note that setuptools is sort of tied with your version of Pip. So you might have to do: python -m pip install -U pip setuptools

2. The next step is to pick the correct command-line environment. What?! I know right, Visual Studio comes with multiple command prompts. 

Select the appropriate Native Tools Command prompt. Navigate to the project folder. Activate the virtual environment and do what you did last before you encountered the compile error.

If you goes to plan then you should get a successful result.