Anaconda环境运行特定.py文件报错:Python路径不存在?
Hey there, let's tackle this issue step by step. The error clearly points to PyCharm trying to access a Python interpreter path that doesn't exist anymore—even though your Anaconda Python 2.7 and 3.6 environments seem to work fine. Here's what you can do to fix it:
1. Verify the actual path of your Anaconda Python 2.7 environment
First, let's confirm where your working Python 2.7 interpreter is actually located:
- Open your terminal (Terminal app on macOS)
- Activate your Python 2.7 environment with:
(Note: If you're using a newer Conda version, you might needsource activate Py2.7conda activate Py2.7instead) - Run the following command to get the real interpreter path:
Save this path—we'll use it later to update PyCharm's configuration.which python
2. Update PyCharm's Run Configuration
PyCharm is still referencing the old, broken path for your eigenfaces script. Let's fix that:
- In PyCharm, click the run configuration dropdown in the top-right corner (it should show "eigenfaces" right now)
- Select Edit Configurations...
- In the window that pops up, locate your
eigenfacesconfiguration in the left sidebar - Look for the Python interpreter field near the top. Check if the path matches what you got from the terminal.
- If it doesn't, click the dropdown menu and select your Python 2.7 environment from the list.
- If the environment isn't listed, click Show All... then the + button to add it manually, pasting the path you copied earlier.
- Click Apply then OK to save the changes. Try running the script again.
3. Fix potential Anaconda environment corruption
If the path from the terminal doesn't match what PyCharm was using, your environment might have been damaged during the system crash. You can recreate the environment safely:
- Deactivate the current environment first:
source deactivate - Remove the old Py2.7 environment (optional but clean):
conda remove -n Py2.7 --all - Create a fresh Python 2.7 environment:
conda create -n Py2.7 python=2.7 - Activate the new environment and reinstall any dependencies your project needs (e.g., if you have a
requirements.txtfile):source activate Py2.7 pip install -r /Users/luka/Dropbox/Luka/Data Analysis/Data Science Nanodegree/P5/ud120-projects-master/pca/requirements.txt - Go back to PyCharm's run configuration and select this fresh environment as the interpreter.
4. Check Dropbox directory permissions
Since your project is stored in a Dropbox folder, there's a chance file permissions are preventing PyCharm from accessing the interpreter or script properly:
- Try copying the entire
pcadirectory to a local folder outside Dropbox (e.g.,/Users/luka/Documents/pca) - Open the copied project in PyCharm and try running the script again. If it works, the issue was related to Dropbox's permissions or syncing.
- If you want to keep using the Dropbox version, you can adjust permissions with this terminal command:
chmod -R 755 /Users/luka/Dropbox/Luka/Data Analysis/Data Science Nanodegree/P5/ud120-projects-master/pca
内容的提问来源于stack exchange,提问作者Trgovec

