-1

When I try to open an spss (.SAV) file in pandas module I get an error message about pyreadstat even I had downloaded the package.

Code:

import pandas as pd
    
print(pd.read_spss('file.SAV'))

Output:

ImportError: Missing optional dependency 'pyreadstat'. Use pip or conda to install pyreadstat.

Could you please tell me how can I solve this problem?

GooDeeJAY
  • 1,681
  • 2
  • 20
  • 27

2 Answers2

0

do In a command line window:

pip install pyreadstat
Otto Fajardo
  • 3,037
  • 1
  • 18
  • 26
  • I did it. Installed pyreadstat succesfully. But having the same error message. I am using pycharm is it something about it? – mete yılmaz Apr 03 '21 at 10:03
  • Yes, probably you have not used the same interpreter when installing pyreadstat and when running your script in pyreadstat, re-check the configuration. – Otto Fajardo Apr 03 '21 at 11:44
  • @OttoFajardo I have the same problem and i only have one python installation. (I already installed the package with pip) – SearchSpace May 02 '21 at 15:48
  • @SearchSpace do the following: open a terminal window (do not use PyCharm, VScode, Jupyter, or any other IDE or editor), type python so that you get into the interpreter, and do import pyreadstat. If it imports correctly then the issue is in the configuration of your IDE. print(pyreadstat.__file__) to know where it is installed and fix the configuration of your IDE. If it does not import, in the terminal window do where(windows)/which(linux/mac) python. It will tell you where python executable is. Then do where/which pip to tell you where pip is. Are both in the same place? – Otto Fajardo May 03 '21 at 08:08
  • Another possibility is that when you installed with pip it actually failed to install, read carefully any error or warning from pip. – Otto Fajardo May 03 '21 at 08:16
  • @OttoFajardo I get an `ImportError: DLL load failed while importing pyreadstat: Das angegebene Modul wurde nicht gefunden.` I found [this thread](https://github.com/Roche/pyreadstat/issues/33) on the github repos. I searched for the .dlls an added them to PATH (so ` echo $Env:PATH` in powershell shows `C:\Users\***\AppData\Roaming\Python\Lib\site-packages\pyreadstat\` [*** is just for privacy masked]) which contains the two dlls). Still get the error. – SearchSpace May 03 '21 at 16:26
  • First make sure you are using the latest version of pyreadstat. If still does not work try changing the PATH like this https://www.computerhope.com/issues/ch000549.htm – Otto Fajardo May 04 '21 at 17:27
0

I changed file format to ".csv" with spss. I can use data in pandas properly now