Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to pandas Meet pandas Accessing a Series

unable to recognize "from utils import render"

when i typed in the first code in notebook , i returned the following info “<ipython-input-16-57fc0e5099b2> in <module> 1 import pandas as pd ----> 2 from utils import render 3 4 test_balance_data = { 5 'pasan':20.00,

ModuleNotFoundError: No module named 'utils'”

anyone knows what's going on?

7 Answers

You also can just copy the utils.py file of github and paste it in your own folder where your jupyter notebook is

Sebastiaan van Vugt
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sebastiaan van Vugt
Python Development Techdegree Graduate 13,554 Points

At first I tried:

pip install python-utils

pip install utils

Then I downloaded Utils from the GitHub repository and did

Import Utils

Since after every step I kept getting errors I just pasted the Utils code in the top cell instead of

from utils import render
from IPython.display import display, Markdown

def render(md):
    return display(Markdown(md))

def make_chaos(df, sample_size, columns, fn):
    # Keep chaos the same randomly
    some = df.sample(sample_size, random_state=sample_size)
    for col in columns:
        some[col] = some[col].apply(fn)
    # Update the original DataFrame
    df.update(some)

After closing and opening my Jupyter notebook I can now also just use

from utils import render

Tested on Windows 10 + Chrome + Jupyter with full Anaconda3 and Python 38-32 installed separately

Stephen Cole
PLUS
Stephen Cole
Courses Plus Student 15,809 Points

Whatever render was, it is not needed

Use PEP 498 f-strings instead

PEP 498 introduced a simpler string formatting mechanism known as Literal String Interpolation. Because of the leading f character preceding the string literal, this is more commonly called an f-string.

To create an f-string, prefix the string with the letter f. The string itself can be formatted in much the same way that you would with str.format().

F-strings provide a concise and convenient way to embed python expressions inside string literals for formatting.

Original

render("The label {} has a value of {}".format(label, value))

F-String

print(f'The label {label} has a value of {value}.')

https://pypi.org/project/python-utils/

The virtual environment or python distribution you are using does not have utils. From your terminal try pip install python-utils

competent- fellow
competent- fellow
5,846 Points

This does not work for me either, after installing both "utils" and "python_utils".

I get following error messages:

"ImportError: cannot import name 'render' from 'utils' (C:\Users\Craig\Anaconda3\lib\site-packages\utils_init_.py)"

"ImportError: cannot import name 'render' from 'python_utils' (C:\Users\Craig\Anaconda3\lib\site-packages\python_utils_init_.py)"

The init.py files are where they should be..

Todd Baker
Todd Baker
17,207 Points

This suggestion didn't solve the issue for me, either. Has anyone been able to install utils?

Also having this issue. I did some snooping and the init.py file is completely empty! I tried installing the most recent utils version as well as the previous two, and all have the same issue. I tried copying Sebastiaan's utils code into the init file, and it did import without throwing an error, however render() is returning an object instead of a string:

<IPython.core.display.Markdown object>

Any reason I should be using render() instead of just a regular print() command? I'm testing my code on Spyder instead of Jupyter Notebooks, so there could be some differences.