joelgrus / data-science-from-scratch

code for Data Science From Scratch book

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ModuleNotFoundError: No module named 'scratch'

emmanuel59 opened this issue · comments

I've got your book and I'm working through it.

I download the whole repo to folder c:\data-science-from-scratch on Windows.

There is the following code in chapter "statistics" from scratch.linear_algebra import sum_of_squares
In anaconda prompt I execute :

(dsfs) c:\data-science-from-scratch>python scratch\statistics.py
Traceback (most recent call last):
File "scratch\statistics.py", line 98, in
from scratch.linear_algebra import sum_of_squares
ModuleNotFoundError: No module named 'scratch'

Do you have some idea to solve the problem ?

Hi emmanuel. I hope this answer is not too late for you and can somehow help you.

The issue arises since scratch is expected to be a module available but cannot be found by the python interpreter. scratch module corresponds to "scratch" folder provided with this repository, and linear_algebra.py is located.

Note: In my case I am not using anaconda but my own virtual environment.

I have this folder structure:
my_workspace
|_ my_venv
|_ scratch (containing all .py files, including linear_algebra.py and init.py, which are relevant here)

I run the following lines from my terminal (I am on Windows, but should work for Linux/MacOS too) in order to make the script work:
cd my_workspace
my_venv\Scripts\activate
set PYTHONPATH=./scratch # For windows
export PYTHONPATH=./scratch # For mac/linux
python3 scratch\ch8_2.py # It should work now