I don’t want to contribute to cpython yet, just build modules. I thought I saw some instructions before but I can’t find them again.
These days, you should just be able to install Visual Studio (select the C compiler, obviously…) and it will get picked up automatically. IIRC, the old instructions were for previous versions which were much trickier to set up.
If you still have problems, I suggest you describe what you’ve done and what went wrong, as that will help people advise you.
Much appreciated. I’ll do as you suggest.
For reference, vs2022 is really weird about this. I successfully created a new project once, but the second time I went to do it the search function didn’t find the option.
I know, an M$ product not behaving as expected. Positively shocking.
Thanks again
Joe
On Windows, I now prefer to build Python with a command line: PCbuild\build.bat -e -d -p x64
:
-
-e
: install dependencies -
-d
: build in debug mode -
-p x64
: build for x86-64 arch (Intel 64 bits)
For me, it’s faster than having to load Visual Studio and use my mouse to click on “build” (and select the right options).
That’s for building Python. For building extensions (which is what the OP asked about) setuptools should automatically detect a correctly-installed copy of Visual Studio with no further configuration needed.
Oh. To build C extensions, you don’t need a whole Visual Studio, but just the Windows SDK to get a C compiler and Windows header files, no?
Possibly, but that is fiddly to set up I think. It’s much easier to just install Visual Studio - the free version is fine.
Rather than start a new topic, I thought I’d build off off this one and flesh it out:
It’s quite tricky to figure out what you need to compile extensions for Windows – that’s probably due to the great work the community is doing with binary wheels, and conda pacakges – so not that many people need to know what to do – but nevertheless, a clear answer here might help.
Well, yes, but “Visual Studio” is not one thing – it is a MASSIVE collection of various stuff you can use for development – .NET apps, web apps, compilers for ARM, the list is very, very long.
I just went through this, and this is what I learned (as of today, Feb 11, 2025):
You need:
Visual Studio 2022:
Which can be downloaded from:
Download: “Visual Studio 2022 Community Edition”
That will give you an installer, and when you run that, you can decide what to install – the whole thing is MASSIVE – you don’t want it all.
There are two options for getting what you need:
Option (1) As documented on: https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.x_with_Visual_Studio_2022_.28x86.2C_x64.2C_ARM.2C_ARM64.29
- Install the Python development workload and the optional Python native development tools option.
The Python native development tools provide the compiler for extensions. The rest of it is to help write Python code.
Option (2)
All you really need is a subset of the “Desktop development with C++” “workload”:
Then you can deselect most of it – keeping:
- C++ core desktop features
- Windows 11 SDK
That should be it. Click install, and wait a lot longer than you’d expect!
Once installed, the various Python build tools should discover it and you’re good to go.
[tested with scikit-build, but hopefully up to date setuptools and meson should work as well]
Happy compiling!
Thanks Chris. Unfortunately the images in your post don’t display…
That’s because they were links to my email account – they looked fine to me!
I think I’ve fixed that – thanks!
Yep, looks good now!
Yeah, nice to have that summary!
But IMHO, this is rather for people who’d like to develop.
If you are only interested in building, see Victor’s post:
That is, in your link
it should be sufficient to scroll down to “Tools for Visual Studio” and then download the “Buildtools for Visual Studio”. For me, this is even enough to rebuild Python itself from source.
And now there is Option 3 – makes it even more confusing!
I actually did look for that, and didn’t find it – thanks for the hint.
Though at a glance it looks like it will give you a LOT more than you need. Which I suppose is no harm other than disk space, and, I’m guessing a really slow download/install process!
I kinda wish MS would provide a single link to a one click download for what you need to obuild Python extensions – like they did back in the day for Python2. Though it IS there, as we see.