如何将Kivy安装到指定的Python站点包目录?
Hey there, let's troubleshoot this Kivy installation problem together—this is a common issue with system-protected Python directories on Windows, so we'll work through it step by step.
1. Resolve Permission Issues First
The C:\Program Files(x86)\Microsoft Visual Studio\Shared\Python35_64 directory is protected by Windows, meaning regular command prompts don't have permission to write to its site-packages folder. Here's how to fix that:
- Open Command Prompt or PowerShell as an administrator: Right-click the start menu entry for your terminal, select "Run as administrator".
- This grants the necessary write access to install packages directly into the system-protected folder.
2. Use the Full Path to Your Python 3.5 Executable
It's easy to have multiple Python versions installed on Windows, which can cause the generic python command to point to a different environment (not your Visual Studio Python 3.5). To avoid this:
- Run this exact command in your admin terminal:
By using the full path to your target Python executable, you ensure pip uses that specific environment—so Kivy will install directly into itsC:\Program Files(x86)\Microsoft Visual Studio\Shared\Python35_64\python.exe -m pip install kivysite-packagesfolder.
3. Upgrade Pip First (Critical for Older Python Versions)
Python 3.5 comes with an outdated version of pip, which often causes installation failures for newer packages like Kivy. Upgrade pip first using your target Python:
C:\Program Files(x86)\Microsoft Visual Studio\Shared\Python35_64\python.exe -m pip install --upgrade pip
Once pip is updated, run the Kivy install command from step 2 again.
4. If All Else Fails: Explicitly Specify the Target Path
If pip still isn't installing to the correct site-packages folder, you can force it with the --target flag:
C:\Program Files(x86)\Microsoft Visual Studio\Shared\Python35_64\python.exe -m pip install kivy --target "C:\Program Files(x86)\Microsoft Visual Studio\Shared\Python35_64\Lib\site-packages"
Note: This is a fallback—using the full Python path (step 2) should normally handle this automatically, so only use this if the previous steps don't work.
Verify the Installation
After completing the steps, confirm Kivy is installed in the right place with this command:
C:\Program Files(x86)\Microsoft Visual Studio\Shared\Python35_64\python.exe -c "import kivy; print(kivy.__file__)"
You should see a path pointing directly to your target site-packages folder if everything worked.
内容的提问来源于stack exchange,提问作者Ivan Minakov

