!wget not working?

Hi Community

I have this code:

import pandas

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

!pip install statsmodels

Load some libraries to do the hard work for us

import graphing

Train (fit) the model so that it creates a line that

fits our data. This method does the hard work for

us. We will look at how this method works in a later unit.

fitted_model = model.fit()

Print information about our model now it has been fit

print(“The following model parameters have been found:\n” +
f"Line slope: {fitted_model.params[1]}\n"+
f"Line Intercept: {fitted_model.params[0]}")


From here: Exercise - Create a machine learning model - Training | Microsoft Learn

got the error:
ModuleNotFoundError: No module named ‘graphing’

That’s not the error you’d get relative to your title. Please focus on the topic you set up in the title first.

What happens when you run the !wget command? What type of system are you running on?

For example, when I go here and press launch binder and then when the session comes up and I open a new notebook and run the following command in a cell:

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

What I see in that sessions is:

--2022-11-02 14:59:47--  https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-learning/main/graphing.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)...,,, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21511 (21K) [text/plain]
Saving to: ‘graphing.py’

graphing.py         100%[===================>]  21.01K  --.-KB/s    in 0.002s  

2022-11-02 14:59:47 (10.2 MB/s) - ‘graphing.py’ saved [21511/21511]

Then if I run ls in a cell, I can see it listed among the files in my current working directory:

graphing.py  LICENSE    requirements.in   runtime.txt
index.ipynb  README.md  requirements.txt  Untitled.ipynb

(Note because pressing the launch binder session there opens a anonymous, temporary Jupyter session in a browser via the MyBInder public service, you can go there and run this to see what I mean if you want. Because it is running on a remote machine, it won’t affect any of the stuff you are doing elsewhere.)

If I then try to import it by running in the next cell import graphing, I see the following:

ModuleNotFoundError                       Traceback (most recent call last)
/tmp/ipykernel_66/3208888535.py in <module>
----> 1 import graphing

~/graphing.py in <module>
      7 from numpy.core.fromnumeric import repeat, shape
      8 import pandas
----> 9 import plotly.express as px
     10 import plotly.io as pio
     11 import plotly.graph_objects as graph_objects

ModuleNotFoundError: No module named 'plotly'

This is because, as advised by Sarah here, I haven’t set up the environment and need to install the necessary package beyond core Python or what comes on a system.

However, that’s getting ahead of ourselves if indeed the !wget command failed like your post title suggests. Because you won’t have graphing in your current working directory and so you cannot import it. However, the rest if you post doesn’t stick to discussing that. You are on what happens when you run import graphing in your post. That’s downstream of the potential issue your post title seems to be directed at.

What happens if you just type in a cell !wget --help?
Curl is an alternative to wget.
What happens if you just type in a cell !curl --help?

Note there are alternatives to wget or curl in this case, too. For example, if I enter https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-learning/main/graphing.py in the address bar of my browser, I can see the text code of the script. If I right-click, I can choose Save as... and save it to my local machine. If the local machine is where you are indeed working, you can then move the file to the working directory and now importing it should work. If you are working on a remote machine, you need to then upload the file from your local machine to the remote machine now. This type of alternative route might get you past the issue in the title of this post .

Related to all this is you can check what is your current working directory by running the following in a cell at any time:


That stands for print working directory. I mentioned already that you can then use ls to see what is among the files in that directory.

Hi Fomightez,
thanks a lot for the help !