最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ImportError: cannot import name 'fetch' from 'js' - Stack Overflow

programmeradmin1浏览0评论

I am working on a coursera IBM project with Jupyter on my Ubuntu 22.04 and having problems with the very first cell of one section:

# Download and read the `spacex_launch_geo.csv`
from js import fetch
import io

URL = '/IBM-DS0321EN-SkillsNetwork/datasets/spacex_launch_geo.csv'
resp = await fetch(URL)
spacex_csv_file = io.BytesIO((await resp.arrayBuffer()).to_py())
spacex_df=pd.read_csv(spacex_csv_file)
spacex_df.head(15)

and get the error:

ImportError: cannot import name 'fetch' from 'js' (/home/tim/.local/lib/python3.10/site-packages/js/__init__.py)

I have made sure to pip install js to my machine. Any ideas would be helpful. The only thing I notice when looking at the mand line for my machine is that is says:

 Requirement already satisfied: js in ./.local/lib/python3.10/site-packages (1.0)

Is this a problem with a global v. local to user installation of js? And if so, what can I do to alleviate the issue. Thank you.

I am working on a coursera IBM project with Jupyter on my Ubuntu 22.04 and having problems with the very first cell of one section:

# Download and read the `spacex_launch_geo.csv`
from js import fetch
import io

URL = 'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/spacex_launch_geo.csv'
resp = await fetch(URL)
spacex_csv_file = io.BytesIO((await resp.arrayBuffer()).to_py())
spacex_df=pd.read_csv(spacex_csv_file)
spacex_df.head(15)

and get the error:

ImportError: cannot import name 'fetch' from 'js' (/home/tim/.local/lib/python3.10/site-packages/js/__init__.py)

I have made sure to pip install js to my machine. Any ideas would be helpful. The only thing I notice when looking at the mand line for my machine is that is says:

 Requirement already satisfied: js in ./.local/lib/python3.10/site-packages (1.0)

Is this a problem with a global v. local to user installation of js? And if so, what can I do to alleviate the issue. Thank you.

Share Improve this question edited Dec 18, 2022 at 16:27 Lakeshore asked Dec 18, 2022 at 15:37 LakeshoreLakeshore 191 silver badge3 bronze badges 3
  • Where from have you got the code from js import fetch ? The project pypi/project/js had the only release in 2012. There is no any code in it so you hardly can import anything from it. – phd Commented Dec 18, 2022 at 15:55
  • It’s from an IBM Data Science course on Coursera. – Lakeshore Commented Dec 18, 2022 at 16:24
  • Then it's a different js, not the one at PyPI. You should find out what is it. – phd Commented Dec 18, 2022 at 16:37
Add a ment  | 

3 Answers 3

Reset to default 4

There's no need to use the js module, just ment on the respective lines and read the file as usual:

# Download and read the `spacex_launch_geo.csv`
#from js import fetch
#import io

URL = 'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/spacex_launch_geo.csv'
#resp = await fetch(URL)
#spacex_csv_file = io.BytesIO((await resp.arrayBuffer()).to_py())
spacex_df=pd.read_csv(URL)
spacex_df.head(15)

Instead of using fetch, use this:

    import requests
    import io
    import pandas as pd
    
    URL = 'https://...'
    resp = requests.get(URL)
    text = io.StringIO(resp.text)
    
    df = pd.read_csv(text)
    print('Data downloaded and read into a dataframe!')

I had the same problem and I did this.

# from js import fetch
import requests
import io

URL = 'https://...'
# resp = await fetch(URL)
resp = requests.get(URL)
# text = io.BytesIO((await resp.arrayBuffer()).to_py())
text = resp.content

df_can = pd.read_excel(
    text,
    sheet_name='sheet_name',
    skiprows=range(20),
    skipfooter=2)
print('Data downloaded and read into a dataframe!')

You need install requests module before. You mey verify your system modules with "pip list" order.

发布评论

评论列表(0)

  1. 暂无评论