Python Forum
How to fix this error: ModuleNotFoundError: No module named 'notears' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to fix this error: ModuleNotFoundError: No module named 'notears' (/thread-40313.html)



How to fix this error: ModuleNotFoundError: No module named 'notears' - yaoyao22 - Jul-09-2023

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/master/notears/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.


RE: How to fix this error: ModuleNotFoundError: No module named 'notears' - snippsat - Jul-09-2023

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}



RE: How to fix this error: ModuleNotFoundError: No module named 'notears' - yaoyao22 - Jul-09-2023

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}