Ask about ModuleNotFoundError: No module named xx in Python.

Asked 2 years ago, Updated 2 years ago, 111 views

I'm inquiring because there's a blockage during Python work.

As I was working on the programming, I imported various useful libraries and used them

Whether the path side is twisted while installing another program or the library is broken

One library that used to work doesn't work

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\Scripts\test.py", line 4, in <module>

   import statsmodels.formula.api as sm

  File "C:\ProgramData\Anaconda3\Scripts\statsmodels.py", line 3, in <module>

    import statsmodels.formula.api as sm

ModuleNotFoundError: No module named 'statsmodels.formula'; 'statsmodels' is not a package

I don't recognize it with the phrase.

 import statsmodels.formula.api as sm

It was imported through that sentence and used.

I thought the library was broken, so I tried uninstalling and reinstalling it using pip, but it is not working the same way.

I'm still inexperienced in the path, so I don't know how to fix it.

I ask for good answers from other masters.

python statsmodels

2022-09-22 12:18

2 Answers

An error called no module usually occurs when you try to import something that is not a module.

In order to import one program that belongs to the module without importing it into the module, you have to tell me where it belongs in the from.

Usually, in Python, one module, one.Recognize as a py extension file. In other words, in order to import it in the form you want, you have to do the following.

from statsmodels import formula as sm

And, I don't know what formula is. If you look at it in the form formula.api and think of it as a function included in the class. Usually, it would be good for your mental health to bring the formula...

I don't know if the formula is a module, but...


2022-09-22 12:18

It's a mistake that Python beginners often make.

From the error message, the same location as the main Python file test.py executed by the file named statsmodels.py is attempted to import the same script from the library statsmodels instead of code>C:\ProgramData\Anaconda3\Scripts\. (The pip installation library files are installed in Lib/site-package/statsmodels and the grinded path.)


2022-09-22 12:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.