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
  Using moviepy fails due to "ModuleNotFoundError: No module named 'pip._internal.utils sheepog 2 2,269 May-28-2025, 06:57 PM
Last Post: sheepog
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 3 5,032 May-10-2025, 05:56 PM
Last Post: Wimpy_Wellington
  ModuleNotFoundError: No module named 'tkcalendar', Thonny, Windows 10 Edward_ 4 5,371 Apr-06-2025, 07:56 PM
Last Post: Edward_
  No module named 'importlib.metadata' EdVS 3 3,054 Jan-30-2025, 09:55 AM
Last Post: Larz60+
  ModuleNotFoundError: No module named 'athena_read' raman 2 2,311 Jul-01-2024, 07:52 AM
Last Post: Gribouillis
  no module named 'docx' when importing docx MaartenRo 1 8,958 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 34,933 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 15,482 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 7,024 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 5,259 Aug-07-2023, 05:32 AM
Last Post: DPaul

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.