Python Forum
How to fix this error: ModuleNotFoundError: No module named 'notears'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix this error: ModuleNotFoundError: No module named 'notears'
#1
I want to run linear.py from the below website. But I always am stuck at line 90 of linear.py. How to fix the error? The linear.py code can be seen here: https://github.com/xunzheng/notears/blob.../linear.py

Traceback (most recent call last):
File "C:\Users\14047\notears\notears\linear.py", line 90, in <module>
from notears import utils
ModuleNotFoundError: No module named 'notears'
[Finished in 2.9s]

This website https://github.com/xunzheng/notears said

> Running a simple demo
The simplest way to try out NOTEARS is to run a simple example:

$ git clone https://github.com/xunzheng/notears.git
$ cd notears/
$ python notears/linear.py
This runs the l1-regularized NOTEARS on a randomly generated 20-node Erdos-Renyi graph with 100 samples. Within a few seconds, you should see output like this:

{'fdr': 0.0, 'tpr': 1.0, 'fpr': 0.0, 'shd': 0, 'nnz': 20}
The data, ground truth graph, and the estimate will be stored in X.csv, W_true.csv, and W_est.csv.

I want to fix the error. Then when I run linear.py, I can get the same output as authors suggest.
Reply
#2
You do as described,need to have Git,and best to do this in a virtual environment.
# Install required packages
(suspender_env) G:\div_code\suspender_env
λ pip install igraph
Collecting igraph
  Downloading igraph-0.10.5-cp39-abi3-win_amd64.whl (2.9 MB)
     ---------------------------------------- 2.9/2.9 MB 5.3 MB/s eta 0:00:00
Collecting texttable>=1.6.2 (from igraph)
  Downloading texttable-1.6.7-py2.py3-none-any.whl (10 kB)
Installing collected packages: texttable, igraph
Successfully installed igraph-0.10.5 texttable-1.6.7

(suspender_env) G:\div_code\suspender_env
λ pip install numpy scipy
Requirement already satisfied: numpy in g:\div_code\suspender_env\lib\site-packages (1.25.0)
Collecting scipy
  Downloading scipy-1.11.1-cp311-cp311-win_amd64.whl (44.0 MB)
     ---------------------------------------- 44.0/44.0 MB 3.1 MB/s eta 0:00:00
Installing collected packages: scipy
Successfully installed scipy-1.11.1

# Get Repo
(suspender_env) G:\div_code\suspender_env
λ git clone https://github.com/xunzheng/notears.git
Cloning into 'notears'...
remote: Enumerating objects: 207, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (13/13), done.
Receiving objects:  90% (187/207)
Receiving objects: 100% (207/207), 77.79 KiB | 1.11 MiB/s, done.
Resolving deltas: 100% (101/101), done.

# Cd in
(suspender_env) G:\div_code\suspender_env

# Test
(suspender_env) G:\div_code\suspender_env\notears (master)
λ python notears/linear.py
{'fdr': 0.0, 'tpr': 0.95, 'fpr': 0.0, 'shd': 1, 'nnz': 19}
Reply
#3
I solve my problem. The original line 90 code is from notears import utils

I change it to import utils

Then the problem is solved. I get the output:
C:\Users\14047\notears>python notears/linear.py
{'fdr': 0.0, 'tpr': 0.95, 'fpr': 0.0, 'shd': 1, 'nnz': 19}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 894 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 23,818 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,604 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,464 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,523 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,348 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  Help with pyinstaller "No module named" korenron 9 9,139 Jun-15-2023, 12:20 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,019 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,869 Oct-20-2022, 02:56 PM
Last Post: deanhystad
  ModuleNotFoundError: No module named '_struct' when starting pip3 yuhuihu 0 2,883 May-05-2022, 04:41 AM
Last Post: yuhuihu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020