Windows10 64位Anaconda Spyder2.7+Psychopy中openpyxl依赖报错求助
Hey there, let’s work through this frustrating openpyxl import issue you’re hitting with PsychoPy on your Python 2.7 setup. I’ve dealt with similar dependency mismatches before, so here are actionable steps to resolve it:
1. Install a Python 2.7-compatible version of openpyxl
Openpyxl dropped support for Python 2.7 starting with version 3.0. If you installed the latest version, it won’t work with your Spyder 2.7 environment. Here’s how to fix this:
- Open Anaconda Prompt
- If you’re using a dedicated environment for PsychoPy, activate it first:
conda activate your_psychopy_env - Install the last openpyxl version that supports Python 2.7:
(If pip doesn’t work, trypip install openpyxl==2.6.4conda install openpyxl==2.6.4instead)
2. Confirm Spyder is using the correct Anaconda environment
Sometimes Spyder defaults to a different Python interpreter than the one where you installed openpyxl/Psychopy:
- In Spyder, go to
Tools > Preferences > Python interpreter - Make sure the selected interpreter path points to the Python.exe in your PsychoPy/Python 2.7 environment (e.g.,
C:\Users\YourUsername\anaconda3\envs\py27\python.exe) - Restart Spyder to apply the change
3. Update all openpyxl imports in PsychoPy’s data.py
You modified one import line, but there might be other outdated references in the file:
- Locate the
data.pyfile in your PsychoPy installation directory (usually underLib\site-packages\psychopy\datain your Anaconda environment) - Search for all instances of
from openpyxl.cell import get_column_letterand replace them withfrom openpyxl.utils import get_column_letter - Save the file and restart Spyder
4. Verify openpyxl installation in Spyder
To double-check everything is set up correctly, run these lines in Spyder’s IPython console:
import openpyxl print("Openpyxl version:", openpyxl.__version__) print("Openpyxl install path:", openpyxl.__file__)
- If you get an import error here, your Spyder environment isn’t pointing to the right installation
- If the version is 2.6.x, you’re good to go; if it’s 3.x, you need to downgrade as step 1 outlines
If you can share the exact code snippet that’s triggering the error and the full traceback, we can narrow down any remaining issues, but these steps should resolve the core problem.
内容的提问来源于stack exchange,提问作者Ravi Mevada

