aws-samples / amazon-bedrock-workshop

This is a workshop designed for Amazon Bedrock a foundational model service.
https://catalog.us-east-1.prod.workshops.aws/amazon-bedrock/en-US
MIT No Attribution
1.45k stars 625 forks source link

Cannot import name 'bedrock' from 'utils' #31

Closed hlmiao closed 1 year ago

hlmiao commented 1 year ago

I experienced the following error after running this line “from utils import bedrock, print_ww” in https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/00_Intro/bedrock_boto3_setup.ipynb

import json
import os
import sys

import boto3

module_path = ".."
sys.path.append(os.path.abspath(module_path))
from utils import bedrock, print_ww
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[4], line 9
      7 module_path = ".."
      8 sys.path.append(os.path.abspath(module_path))
----> 9 from utils import bedrock, print_ww

ImportError: cannot import name 'bedrock' from 'utils' (/home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/utils/__init__.py)
%pip install utils
Looking in indexes: https://pypi.org/simple, https://pip.repos.neuron.amazonaws.com/
Collecting utils
  Using cached utils-1.0.1-py2.py3-none-any.whl (21 kB)
Installing collected packages: utils
Successfully installed utils-1.0.1
Note: you may need to restart the kernel to use updated packages.
%pip install bedrock

error: Command "gcc -pthread -B /home/ec2-user/anaconda3/envs/pytorch_p310/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/ec2-user/anaconda3/envs/pytorch_p310/include -fPIC -O2 -isystem /home/ec2-user/anaconda3/envs/pytorch_p310/include -fPIC -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DSCIPY_MKL_H -DHAVE_CBLAS -I/usr/local/include -I/usr/include -I/home/ec2-user/anaconda3/envs/pytorch_p310/include -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.1/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/home/ec2-user/anaconda3/envs/pytorch_p310/include/python3.10 -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Ibuild/src.linux-x86_64-3.1/numpy/core/src/npymath -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Ibuild/src.linux-x86_64-3.1/numpy/core/src/npymath -Ibuild/src.linux-x86_64-3.1/numpy/core/src/private -Ibuild/src.linux-x86_64-3.1/numpy/core/src/npymath -c build/src.linux-x86_64-3.1/numpy/core/src/multiarray/scalartypes.c -o build/temp.linux-x86_64-cpython-310/build/src.linux-x86_64-3.1/numpy/core/src/multiarray/scalartypes.o -MMD -MF build/temp.linux-x86_64-cpython-310/build/src.linux-x86_64-3.1/numpy/core/src/multiarray/scalartypes.o.d" failed with exit status 1
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for numpy
        Running setup.py clean for numpy
        error: subprocess-exited-with-error

        × python setup.py clean did not run successfully.
        │ exit code: 1
        ╰─> [10 lines of output]
            Running from numpy source directory.

            `setup.py clean` is not supported, use one of the following instead:

              - `git clean -xdf` (cleans all files)
              - `git clean -Xdf` (cleans all versioned files, doesn't touch
                                  files that aren't checked into the git repo)

            Add `--force` to your command to use it anyway if you must (unsupported).

            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed cleaning build dir for numpy
      Failed to build numpy
      ERROR: Could not build wheels for numpy, which is required to install pyproject.toml-based projects

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
Note: you may need to restart the kernel to use updated packages.
MAGICALAMIGO-HUB commented 12 months ago

for that replace that utils with https://github.com/MAGICALAMIGO-HUB/utils_for_bedrock just take the utils folder and replace it to your location /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/utils/

Dinuda commented 10 months ago

Please use boto3. I have included the solution at Pr 159.

For a simpler version I have created a sample setup guide until this gets merged at BedrockBoto3Setup

shahramjoon commented 8 months ago

it doesn't look it is merged because today March 1, i cloned repo and the problem is still there

if i am experiencing the error in sagemaker studio , how can i add your utils package there

I am getting the error when i am running this python in sagemaker in my aws account.

https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/00_Intro/bedrock_boto3_setup.ipynb

Dinuda commented 8 months ago

Unfortunately, the team still hasn't reviewed. Can you try cloning the repo that I have inserted in the above comment?

shahramjoon commented 8 months ago

how can i clone it? that is my question. please answer in the context that I am running this in sagemaker https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/00_Intro/bedrock_boto3_setup.ipynb

your instruction is saying put it in a specific folder but because i am running it in sagemaker cloud, i don't have access to the location you are saying.

Dinuda commented 7 months ago

Use this file: https://github.com/Dinuda/BedrockBoto3Setup/blob/main/setup.ipynb