OSX系统下使用./configure指定目录安装Python3.8.6失败求助
Hey there! Let's figure out why your Python install isn't landing in the right folder, and get it sorted out properly.
First, let's clear up what ./configure actually does
You didn't misunderstand it entirely, but you might have missed a couple critical steps after running it. The ./configure command doesn't install Python—it just sets up configuration files (like the Makefile) that tell the subsequent make and make install commands where to put the final files, and what features to include in the build.
Step-by-Step Correct Installation Flow
Let's walk through the full process from scratch to make sure you hit all the right buttons:
Prepare your target directory (make sure it exists, just to avoid permission/creation issues):
mkdir -p /Users/myusername/Desktop/PythonProjectsNavigate to your extracted Python source directory:
cd ~/Downloads/Python3.8.6Clean any previous build artifacts (if you ran
makebefore, this ensures no old files mess things up):make cleanConfigure the build with your desired install path:
./configure --prefix=/Users/myusername/Desktop/PythonProjectsYou should see output here confirming the configuration settings—keep an eye out for lines mentioning the prefix path to make sure it's correct.
Compile the Python source code:
makeThis will take a few minutes, as it builds all the Python binaries and libraries in your current
~/Downloads/Python3.8.6directory.Install the compiled files to your target folder:
make installThis is the step that actually copies all the built files into the
PythonProjectsdirectory you specified. After running this, check the target folder—you should seebin,lib,include, andsharesubfolders there.
Setting This Python Version as Your System Default
Once installed, you need to tell macOS to use this version instead of the system's default Python. Never modify the system's built-in Python (it can break system tools like brew or macOS utilities). Instead, update your shell's PATH:
Open your shell configuration file—if you use Zsh (default on newer macOS), edit
~/.zshrc; if you use Bash, edit~/.bash_profile:nano ~/.zshrcAdd this line at the bottom to prioritize your custom Python install:
export PATH="/Users/myusername/Desktop/PythonProjects/bin:$PATH"Save and exit (in nano:
Ctrl+O, press Enter, thenCtrl+X).Reload the configuration to apply changes immediately:
source ~/.zshrcVerify it worked:
which python3 # Should output: /Users/myusername/Desktop/PythonProjects/bin/python3 python3 --version # Should output: Python 3.8.6
Common Pitfalls to Check
- If you only ran
./configureand stopped there: That's why files stayed in your Downloads folder—you never told it to compile and install! - Permission errors during
make install: If you see permission denied messages, you might need to runsudo make install, but only if your user doesn't have write access to thePythonProjectsfolder (though you should own your Desktop, so this shouldn't be necessary). - Old build files interfering: Always run
make cleanif you reconfigure the build, to avoid leftover files from previous attempts.
内容的提问来源于stack exchange,提问作者spizzi

