ModuleNotFoundError-如何安装Python3软件包以使我的用户数据脚本获得';他被处决了?

ModuleNotFoundError-如何安装Python3软件包以使我的用户数据脚本获得';他被处决了?,python,python-3.x,amazon-web-services,amazon-ec2,Python,Python 3.x,Amazon Web Services,Amazon Ec2,我正在尝试在EC2用户数据中运行python脚本。我正在启动的EC2实例使用我修复的自定义AMI映像。我通过执行这些命令安装了我需要的两个包-boto3和pyodbc包(注意,我将它们安装为root): 我的用户数据脚本: #!/bin/bash set -e -x # set AWS region echo "export AWS_DEFAULT_REGION=${region}" >> /etc/profile source /etc/profile # c

我正在尝试在EC2用户数据中运行python脚本。我正在启动的EC2实例使用我修复的自定义AMI映像。我通过执行这些命令安装了我需要的两个包-
boto3
pyodbc
包(注意,我将它们安装为
root
):

我的用户数据脚本:

#!/bin/bash
set -e -x

# set AWS region
echo "export AWS_DEFAULT_REGION=${region}" >> /etc/profile
source /etc/profile
# copy python script from the s3 bucket
aws s3 cp s3://${bucket_name}/ /home/ec2-user --recursive

/usr/bin/python3 /home/ec2-user/my_script.py
在启动新的EC2实例(使用my custom AMI)并检查
/var/log/cloud init output.log
后,我发现错误:

+ python3 /home/ec2-user/main_rigs_stopgap.py
Traceback (most recent call last):
  File "/home/ec2-user/my_script.py", line 1, in <module>
    import boto3
ModuleNotFoundError: No module named 'boto3'
util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
+python3/home/ec2 user/main\u rigs\u stoppag.py
回溯(最近一次呼叫最后一次):
文件“/home/ec2 user/my_script.py”,第1行,在
进口boto3
ModuleNotFoundError:没有名为“boto3”的模块
util.py[警告]:无法运行/var/lib/cloud/instance/scripts/part-001[1]
cc_scripts_user.py[警告]:无法运行模块脚本用户(在/var/lib/cloud/instance/scripts中的脚本)
util.py[警告]:运行模块脚本用户()失败

有什么建议吗?

要确保您安装的模块是正确的python版本,请使用您正在使用的python版本的内置
pip
模块:

/usr/bin/python3 -m pip install module_name
/usr/bin/python3 -m pip install module_name