Beginner problem running code from MS

Hi jupyer com.
I im trying to run the code from microsoft certification “Exercise - Create a machine learning model - Training | Microsoft Learn” in my jupyter notebook. I have installed anaconda and opened jupyter from there.

Error:

question: can I use jupyter to run code instead of opening a sandbox and run it there?

I am just trying to run the code in my own jupyter notebook, but without much luck :frowning:

lets take an example of code i cant run in my jupyter notebook

///
import pandas

!wget https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-learning/main/graphing.py

!wget https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-learning/main/Data/doggy-boot-harness.csv

Read the text file containing data using pandas

dataset = pandas.read_csv(‘doggy-boot-harness.csv’)

Print the data

Because there are a lot of data, use head() to only print the first few rows

dataset.head()

///

from Exercise - Create a machine learning model - Training | Microsoft Learn does not work “import graphing”

You will need to install graphing (and any other packages required) before you can run the code. This is because graphing is not a package in Python’s standard library, so you have to install it separately.

Since you already have anaconda installed, you can create an isolated environment to install these dependencies and run the notebook from. Something like:

conda env create --name mslearn jupyter graphing  # Add other packages to the end of this line
conda activate mslearn
jupyter notebook

In the above example, mslearn is the name we give to the environment we create so we can reference it.

Once you have created and activated your conda environment, you can install more packages with one of these two commands:

conda install PACKAGE_NAME  # conda native command
pip install PACKAGE_NAME  # Using pip instead of conda

Read more about conda environments here:

There may be a requirements.txt file with the notebooks, wherever you downloaded them from. This is a plain text file that lists all the dependent packages required to run the code that don’t ship with the standard library. You can install those packages into your conda environment like so:

conda activate mslearn  # You can skip this if your environment is already active
pip install -r requirements.txt
1 Like

I posted over in your other thread about wget not working. The reason you cannot import graphing is because if you don’t somehow retrieve the script and have it listed among the files in your current working directory (or installed a package called ‘graphing’ in your environment as @sgibson91 was suggesting – although is not the case here because there is a specific script file graphing.py that was supposed to be obtained), then running the import graphing command is going to fail with the Module not found error you see.

All that is to say though what I stress in the other thread where you seemed more onto the underlying issue. You have to FIRST get the file graphing.py into the working directory of where you are working on this notebook. Steps that are downstream that thwn try to work with the graphing.py script file will fail because that Python script file isn’t present.