首页 > 解决方案 > Python3 找不到 statsmodels.api 但我可以,我的 linter 也可以

问题描述

我最近开始使用在 WSL(Ubuntu 18.04 LTS)上运行的 Python 进行开发。

我按照此处的文档进行操作,并且能够运行简单的 python 脚本。

我开始玩弄我使用pip3命令安装的库,例如numpyandpandas这些工作正常。

当我尝试使用该statsmodels软件包时会出现问题。我已经安装了它pip3 install statsmodels

我可以看到包,/home/username/.local/lib/python3.6/site-packages/statsmodels我什至可以看到该api.py目录中的文件,但是,当我按照statsmodels 网站import statsmodels.api as sm上的建议键入时,我得到:

错误

控制台输出:

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

我试过卸载并重新安装(没有用)

我真的看不出有什么可以将这个软件包与我安装的其他软件包区分开来。有没有人有任何见解?

标签: pippython-3.6statsmodels

解决方案


谢谢@Vorsprung durch Technik

问题是我的文件名是 statsmodels.py。

我会记得在命名我的 python 文件时要更加小心。


推荐阅读