.py file will not load up in jupyter notebook

For the NLP “Machine Translation” project, we were given a work file that ends with .py

When I load the .py file in Jupyter Notebook, from the linux prompt, I get this error message, “%load preprocessing.py fg: job not found: load”

When I load in that .py file, from within Jupyter Notebook, none of the tools show up, to run the code. It just appears like it is a text file that you read.

So, I cannot enter code, and complete this assignment.

Anyone know how to fix? Thanks.

The .py file is a text file.

Have you tried:

%load filename.py #make sure you have the correct filepath

in Jupyter and ran the cell?

For reference:

Additionally, you could also copy+paste the code from the .py file into a juypter notebook cell.

And, if you do a %lsmagic you can see all the available magic commands.

Check here as well:

Thanks for your help. It turns out that the problem is that my Mac finder window can see the files, but my Linux Terminal Shell cannot see the .py files. So, I will have to try to do the copy-n-paste method, to get that code in to Jupyter Notebook.

Follow up:

Thank you again.

So, after launching jupyter-notebook from the Terminal, in the path where the .py files live,
Then
Updating software for Anaconda-Navigator, I opened Jupyter Notebook (again) from the Anaconda-Navigator app.
Then
I went back to the shell, and the .py files were there.
Then
at the Terminal, I did this:
pip install jupytext
jupytext --to notebook preprocessing.py
jupytext --to notebook training_model.py
jupytext --to notebook test_function.py

And now I have three .ipynb files. Fixed. Thank you.

1 Like

It sounds like there might be an issue with how you’re trying to load the .py file into Jupyter Notebook. Instead of using %load preprocessing.py, try using the open() function to open the file and then execute it cell by cell. Here’s what you can do:

# Open the .py file
with open('preprocessing.py', 'r') as file:
    code = file.read()

# Execute the code cell by cell
exec(code)

This should load the contents of the .py file into Jupyter Notebook, allowing you to run the code and complete your assignment. Let me know if you need further assistance!