How do I run a python script on a Sagemaker notebook instance?

0

I have a python script that I would like to run from a terminal attached to my sagemaker notebook instance. I'm using the provided Data Science 3.0 image on a t3.medium.

My process:

  1. Start the notebook instance
  2. Launch terminal using icon in notebook toolbar
  3. Activate conda environment (base)
  4. Run script with: python myscript.py arg1

At this point I receive this error: ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /opt/conda/lib/python3.10/site-packages/pandas/_libs/window/aggregations.cpython-310-x86_64-linux-gnu.so)

The above error stems from a simple import sagemaker statement

The import runs perfectly fine in the notebook, however in the terminal I get the error. From what I can tell the kernel and system path are both identical. Running !python myscript.py arg1 from inside the notebook also returns the same error. What am I missing?

JohnB
已提問 6 個月前檢視次數 1944 次
1 個回答
0

Hi - Thanks for reaching out. In the notebook can you please run !which python and !echo $PATH to determine the Python interpreter and path being used. Can you please also do the same in the terminal and compare the outputs?

profile pictureAWS
專家
已回答 6 個月前
  • Hi! So the kernels are the same, however the paths are in fact different. The notebook has the following paths that the terminal is missing: /opt/amazon/bin:/tmp/miniconda3/condabin:/tmp/anaconda3/condabin:/tmp/miniconda2/condabin:/tmp/anaconda2/condabin:/tmp/mambaforge/condabin I tried appending the above paths to the terminal system path, however I receive the same error. In fact, the above directories do not seem to exist within the terminal.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南