Search code examples
pippython-3.6statsmodels

Python3 cannot find statsmodels.api but I can and so can my linter


I recently got into development with Python running on WSL (Ubuntu 18.04 LTS).

I followed the documentation from here and I'm able to run simple python scripts.

I started playing around with libraries that I installed using the pip3 command such as numpy and pandas and these work fine.

The problem arises when I try to use the statsmodels package. I've installed it using pip3 install statsmodels

I can see the package in /home/username/.local/lib/python3.6/site-packages/statsmodels I can even see the api.py file in that directory, however, when I type import statsmodels.api as sm as recommended on the statsmodels website I get:

error

Console output:

username@DESKTOP-1JP4BIE:/mnt/c/users/username/dev/project/playground$ python3 statsmodels.py 
Traceback (most recent call last):
  File "statsmodels.py", line 5, in <module>
    import statsmodels.api as sm
  File "/mnt/c/username/chris/dev/project/playground/statsmodels.py", line 5, in <module>
    import statsmodels.api as sm
ModuleNotFoundError: No module named 'statsmodels.api'; 'statsmodels' is not a package

I've tried uninstalling and reinstalling (did not work)

I really can't see anything that differentiates this package from the others that I've installed. Does anyone have any insights?


Solution

  • Thanks @Vorsprung durch Technik

    The issue was that my file name was statsmodels.py.

    I'll remember to be more careful when naming my python files.