1

I'm running python 3.6 and have statsmodels installed in ./anaconda/lib/python3.6/site-packages however when I try to import statsmodels in python I get the error: "No module named 'statsmodels'". Can someone explain what I'm supposed to do?

I'm using Sublime Text's built in command line interface.

briancaffey
  • 2,339
  • 6
  • 34
  • 62
bwad
  • 71
  • 3
  • 16
  • 1
    what is the output of running `pip freeze | grep statsmodels` in your terminal? – briancaffey Dec 21 '17 at 05:30
  • @briancaffey it returns `statsmodels==0.8.0` – bwad Dec 21 '17 at 05:34
  • 1
    OK. are you running the code in a Jupyter notebook environment and/or with a virtual environment? – briancaffey Dec 21 '17 at 05:38
  • @briancaffey No I'm running it locally – bwad Dec 21 '17 at 05:39
  • 1
    It is not necessary, but I don't have much other information about why the import is failing. One more idea: run the following command in the python interpreter you are using: `import sys; sys.executable`. what is the output? – briancaffey Dec 21 '17 at 05:44
  • @briancaffey /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 – bwad Dec 21 '17 at 05:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161676/discussion-between-briancaffey-and-bernardo-rodriguez). – briancaffey Dec 21 '17 at 05:49

1 Answers1

1

The issue here is that Sublime Text's CLI and your terminal point to different versions of Python.

In your terminal the result of import sys; sys.executable is

/Users/username/anaconda/bin/python'

but in the Sublime Text CLI you would see:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python‌​3

The Sublime Text CLI python path does not have the statsmodels package whereas the anaconda python does. It is possible to change the default python path in Sublime Text. See this question for more details on how to do that. I would recommend just running python from your terminal and not the sublime text CLI to keep things simple.

briancaffey
  • 2,339
  • 6
  • 34
  • 62