Why Install Visual Studio Community?
You may have heard of Visual Studio, often hailed as the "ultimate IDE" (Integrated Development Environment) with powerful features. However, it can also be quite "bulky." For those who aren't specifically doing .NET development, installing the full version usually isn't necessary.
But! If you frequently need to try running open-source AI projects (such as Python-based projects) on your Windows computer, installing Visual Studio Community becomes almost essential. This is because many Python libraries (called "dependencies") require a "compilation" step during installation, which relies on Microsoft's C++ compilation tools (MSVC). If your computer doesn't have the MSVC environment installed, installing these Python libraries will fail, displaying error messages like the following:
Fortunately, the easiest and most recommended way to install the MSVC compilation environment is to install the free Visual Studio Community version. Let's see how to do it.
Step 1: Download the Visual Studio Installer
- Open your browser and visit this address:
https://visualstudio.microsoft.com/zh-hans/free-developer-offers/
- On the page, find the
Visual Studio Community
section and click the "Free download" button below it.
- After the download is complete, find the downloaded
.exe
file (usually starting withVisualStudioSetup
or a similar name) and double-click it to run it.
- A small prompt window may appear, click "Continue". The installer will prepare for a while.
- Next, you will see the main interface of the Visual Studio Installer. It will display the different Visual Studio versions available for installation. Make sure you are under the "Available" tab and find the option with
Visual Studio Community
(e.g.,Visual Studio Community 2022
). This version is completely free, while other versions (such as Professional or Enterprise) require payment. Select the latest Community version (e.g., 2022 or a newer version) and click the "Install" button corresponding to it.
Step 2: Select the Components to Install
After clicking "Install", you will enter a more detailed settings interface where you can choose the specific features you want to install, which are called "Workloads".
- In this interface, scroll down and find the large category named "Desktop & Mobile".
- Under this category, find and check "Desktop development with C++". This is the key to installing the MSVC compilation environment.
- After checking "Desktop development with C++", look at the right side of the window. There will be an "Installation details" area, listing the specific components that will be installed. Most of the necessary components have been automatically checked.
- (Important Recommendation) In the "Installation details" on the right, find and additionally check those options that contain the words "build tools" and "MSVC v14x ... build tools" in their names (e.g., v140, v141, v142, v143, etc.). Refer to areas 4, 5, and 6 in the red box in the image below (the specific numbers and versions may vary slightly, the key is to look at the names).
**Why select these extra items?** Because some older Python projects may depend on specific versions of the MSVC compiler. To avoid compilation errors caused by missing a particular version in the future, it is recommended to select the build tools for several major MSVC versions (v142, v143, etc.) here. Doing so will only take up a little more disk space, but it can save a lot of trouble in the future.
- After confirming that the selection is correct, click the "Install" button in the lower right corner of the interface.
Step 3: Wait for the Installation to Complete
Now, the installer will start downloading and installing all the components you selected. This process will take some time, depending on your network speed and computer performance. Please be patient.
The installer will notify you when the installation is complete. At this point, you can close the Visual Studio Installer.
Done! Visual Studio Community (and most importantly, the C++ compilation environment) has been successfully installed on your computer! Now, go back to the pip install
command that previously failed due to the lack of MSVC and try running it again. It should now pass successfully!