ImportError: Pandas requires ver 3.0.7 or newer of openpyxl

Hi all,

I am new to PsychoPy and I have been building an experiment that uses some code components which import the pandas package. I am on macOS Ventura 13.5 and I’m running PsychoPy v2023.2.2, standalone. When I try to run this experiment, it fails and gives me this error:

ImportError: Pandas requires version '3.0.7' or newer of 'openpyxl' (version '3.0.5' currently installed).

However, I have openpyxl version 3.1.2 installed, and I’ve confirmed this in the PIP terminal using pip show openpyxl. I have also tried uninstalling and reinstalling openpyxl, and also installing specifically version 3.0.7, but I still get the same error. Why is it seeing version 3.0.5 and how do I fix this? Thanks!

Experiment file (code component using Pandas, taken from ChatGPT, is only in the first routine)
VWFA_task_psychopy.psyexp (171.1 KB)

Were you able to fix this issue? I am having the same problem and have uninstalled / reinstalled openpyxl multiple times as version 3.0.7.

I have the same issue. Does anyone solve it?

We are also having the same error! Can someone from the Psychopy team please help us?

Hello, I figured out a solution to this problem that circumvents pandas dependency on openpyxl.

I tried everything (updating openpyxl on my computer, trying to update the version on psychopy, trying different versions of psychopy) but nothing worked.

So, I decided to no longer call openpyxl through pandas in my code anymore. I use them as separate packages now.

Here is my code to help you understand:

OLD CODE THAT REQUIRED PANDAS TO DEPEND ON OPENPYXL:
import pandas as pd
original_file = pd.read_excel(‘Condition.xlsx’) ## THE CULPRIT - requires pandas to pull an openpyxl function

Filter rows with values similar to the participants id

condition_file = original_file.loc[ original_file[‘Run’] == int(expInfo[‘run’]) ]

write your condition file as a csv file

condition_file.to_excel(‘condition_file.xlsx’, index = None, header=True)

NEW CODE THAT USES PANDAS AND OPENPYXL SEPARATELY:
import openpyxl as op
import pandas as pd

original_file = op.load_workbook(filename = ‘Condition.xlsx’)
sheet = original_file.active #get the active sheet (the first available sheet, which is our data)
#rows = sheet.max_rows
#col = sheet.max_column

allCells = [[cell.value for cell in row] for row in sheet.iter_rows()]
print(‘-----Numpy Array Shape’, len(allCells), len(allCells[0]))
conditions = pd.DataFrame(columns = allCells[0], data = allCells[1:])
condition_file = conditions.loc[ conditions[‘Run’] == int(expInfo[‘run’]) ]
condition_file.to_excel(‘condition_file.xlsx’, index = None, header=True)


Hope this helps!