Cannot import xlwings for a code

I tried to import xlwings for a code but I received the following “ModuleNotFoundError: No module named 'xlwings” when I hit ‘run’.

It is located here: xlwings in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages; I used this to find out what python interpreter is being used:
import sys print(sys.executable) and it indicated the following: /Applications/PsychoPy3.app/Contents/MacOS/python

Any idea what’s wrong with my actions?

I think the most probable thing, as Jon said in the GitHub post, that you have multiple Python installations. You have Python 3.6 installed in your /Library/Frameworks directory, and then you have your Python installation in your PsychoPy standalone at /Applications/PsychoPy3.app/Contents/MacOS/python. The xlwings library is not distributed with the standalone PsychoPy, and if you have installed it, you have installed it into Python 3.6, which is separate from PsychoPys Python interpreter.

Are you attempting to import your xlsm conditions file? If so, you could just the Pandas library, which comes with the PsychoPy standalone. Example:

import pandas as pd

myData = pd.read_excel("myExcelFile.xlsm")

This will load your data as a Pandas dataframe, see docs - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html

1 Like