Mac安装Python后执行代码提示[Errno 13] Permission denied的解决方法
Hey there, let's work through this permission denied error you're hitting when running a Build in Sublime Text after setting up Python on your Mac. Here are actionable steps to fix it:
1. Verify Python Interpreter Permissions
First, check if the Python 3.5 interpreter you're using has execution rights. Open up Terminal and run:
ls -l /usr/local/bin/python3.5
Look at the permission string (the first column of the output). If you don't see an x in the user, group, or others section (like -rw-r--r--), you need to add execute permissions:
sudo chmod +x /usr/local/bin/python3.5
When prompted, enter your Mac user password (Terminal won't show characters as you type—this is normal).
2. Resolve Python Version Conflicts
Looking at your path, there are multiple entries for Python 3.6, but your Build command is calling Python 3.5. This mismatch can cause permission or execution issues. Let's align Sublime with your system's default Python 3:
- First, confirm which Python 3 your system uses by running in Terminal:
You'll likely get a path pointing to Python 3.6, likewhich python3/Library/Frameworks/Python.framework/Versions/3.6/bin/python3. - Now update your Sublime Build System to use this default:
- In Sublime Text, go to
Tools→Build System→New Build System. - Replace the default text with this JSON:
{ "cmd": ["python3", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" } - Save the file as
Python3.sublime-build(the default save location is correct:Packages/User). - Select this new build system via
Tools→Build System→Python3, then re-run your Build.
- In Sublime Text, go to
3. Check Your Script's File Permissions
It's possible your test-module.py file doesn't have read permissions for Sublime to access it. Verify with:
ls -l /Users/peter/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/test-module.py
If read permissions are missing, add them with:
chmod +r /Users/peter/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/test-module.py
4. Temporary Fix: Run Sublime with Admin Rights (Not Recommended Long-Term)
If the above steps don't work immediately, you can try launching Sublime with elevated permissions to bypass the issue temporarily. In Terminal, run:
sudo open /Applications/Sublime\ Text.app
Enter your password when prompted, then try your Build again. Note: This is a quick workaround—fixing the root permission/version issues is better for long-term stability.
内容的提问来源于stack exchange,提问作者Morten Rongsted

