3

I tried using the read_SPSS command, but it didn't work. The error seems to be telling me that I need pyreadstat, but I'm unable to even install that. Why, though, would I need pyreadstat? Isn't the ability to read .sav just built into Pandas these days? I'm confused...

Here's the error text I get when I try using read_SPSS:


ImportError                               Traceback (most recent call last)
<ipython-input-33-935d54be8b7a> in <module>
----> 1 twitter=pd.read_spss('twitter_study.sav')

/opt/anaconda3/lib/python3.8/site-packages/pandas/io/spss.py in read_spss(path, usecols, convert_categoricals)
     34     DataFrame
     35     """
---> 36     pyreadstat = import_optional_dependency("pyreadstat")
     37 
     38     if usecols is not None:

/opt/anaconda3/lib/python3.8/site-packages/pandas/compat/_optional.py in import_optional_dependency(name, extra, raise_on_missing, on_version)
    108     except ImportError:
    109         if raise_on_missing:
--> 110             raise ImportError(msg) from None
    111         else:
    112             return None

ImportError: Missing optional dependency 'pyreadstat'.  Use pip or conda to install pyreadstat.
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
RebelX0024
  • 31
  • 1
  • 2

4 Answers4

5

What is built into pandas.read_spss() can be seen here.

The error message you are getting is a bit misleading as it suggests pyreadstat is optional, but the source code shows that pandas.read_spss() relies entirely on pyreadstat.

The easiest way to solve this would therefore be to install pyreadstat.

Wouter
  • 3,201
  • 6
  • 17
  • Thing is, as I said, I can't install pyreadstat. I've tried doing it through both Anaconda and Pip, to no avail. Any help here? – RebelX0024 Apr 17 '21 at 16:43
  • Another note, I can't even find pyreadstat in Anaconda Navigator as an uninstalled package. What does this even mean? Are there any workarounds here? – RebelX0024 Apr 17 '21 at 18:04
  • What error do you get when you try `pip install pyreadstat`? – Wouter Apr 17 '21 at 18:51
  • The strange thing is, I don't even get an error. I run pip or conda install through Terminal (I'm on a Mac) and nothing happens. – RebelX0024 Apr 18 '21 at 04:28
  • @RebelX0024 Using raw python installtion without anacond and installed the package with pip. I still get the same ImportError error. – SearchSpace May 02 '21 at 15:51
1

For those who are reading now, use

conda install -c conda-forge pyreadstat

it works well.

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
0

I had the same issue, couldn't pip install or conda install, you can't find it through Anaconda Navigator and it's not listed here https://repo.anaconda.com/pkgs/main/

It got solved by running the following command mentioned by @埃塞ABELA in the conda powershell prompt

conda install -c conda-forge pyreadstat
makrbec
  • 31
  • 2
0

I solved by using these packages, try this command:

conda install -c conda-forge pyreadstat

If the above command does not work, try this instead:

conda install -c "conda-forge/label/cf202003" pyreadstat