Data Analysis with Python Projects - Sea Level Predictor

Tell us what’s happening:
Describe your issue in detail here.
My code passed the test when ran on my local computer. But it raised an import error when ran on Replit.

Below is the error information:
Traceback (most recent call last): File "main.py", line 2, in <module> import sea_level_predictor File "/home/runner/boilerplate-sea-level-predictor/sea_level_predictor.py", line 1, in <module> import pandas as pd File "/home/runner/boilerplate-sea-level-predictor/venv/lib/python3.8/site-packages/pandas/__init__.py", line 182, in <module> import pandas.testing File "/home/runner/boilerplate-sea-level-predictor/venv/lib/python3.8/site-packages/pandas/testing.py", line 7, in <module> from pandas.util.testing import ( File "/home/runner/boilerplate-sea-level-predictor/venv/lib/python3.8/site-packages/pandas/util/testing.py", line 27, in <module> import pandas._libs.testing as _testing File "pandas/_libs/testing.pyx", line 10, in init pandas._libs.testing File "/home/runner/boilerplate-sea-level-predictor/venv/lib/python3.8/site-packages/numpy/__init__.py", line 284, in __getattr__ raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'bool'
Your code so far
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import linregress

def draw_plot():

Read data from file

df = pd.read_csv(“epa-sea-level.csv”)
result_whole = linregress(df[“Year”], df[“CSIRO Adjusted Sea Level”])
recent = df[df[“Year”] >= 2000]
result_recent = linregress(recent[“Year”],
recent[“CSIRO Adjusted Sea Level”])
years = pd.Series(range(1880, 2051), name=“year”)

Create scatter plot

fig, ax = plt.subplots(figsize=(20, 6))
ax.scatter(df[“Year”],
df[“CSIRO Adjusted Sea Level”],
color=“gray”,
label=“Original”)

Create first line of best fit

ax.plot(years,
years * result_whole.slope + result_whole.intercept,
color=“lightblue”,
label=“Fitted with whole data”)

Create second line of best fit

ax.plot(years[-51:],
years[-51:] * result_recent.slope + result_recent.intercept,
color=“red”,
label=“Fitted with data since 2000”)

Add labels and title

ax.set_xlabel(“Year”)
ax.set_ylabel(“Sea Level (inches)”)
ax.set_title(“Rise in Sea Level”)
plt.legend()

Save plot and return data for testing (DO NOT MODIFY)

plt.savefig(‘sea_level_plot.png’)
return plt.gca()

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Data Analysis with Python Projects - Sea Level Predictor

Link to the challenge:

Both this problem and your other thread are the result of dependency problems. Search the forums about these projects and you should find numerous posts with the solutions, which are roughly fix the python version in pyproject.toml and delete and reinstall the dependencies.

Please post your errors and code in code blocks for proper formatting. With replit.com problems, post a link to your repl.

Got it. Thank you. Will try to figure it out

I tried to fix it. But failed.
Would you please have a look at be low replit.com link:
boilerplate-sea-level-predictor - Replit

Thank you. I finally figured it out. I am wondering why the stuff didn’t update these files to make it work in the first place.

Dependencies are configured by the developer just like anything else. So when the python version is set at 3.7 as it is in some of these project’s pyproject.toml files, then that limits the versions of dependencies allowed to be installed. For instance, current versions of seaborn require python 3.9 or later. It’s typical to have to check python’s and dependencies’ versions in a python project and possibly modify and update them.

The only fix for this problem is to update the boilerplate code for the projects to reflect current versions but this convenience has to be weighed against the opportunity for dependency management.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.