首页 > 解决方案 > 成功安装 pip 后,aws cli 在 Jupyter 中不起作用?

问题描述

我有一个运行 Python 3.7 的 Anaconda 环境

我有一个带有以下行的 Jupyter 笔记本:

!aws configure [....] #Can't display the rest of the code for privacy reasons

当我运行代码块时,我得到:

/bin/sh: aws: command not found

尽管已经运行:

pip install awscli

成功地。

我该如何解决/调试这个?


我已经设法将其归结为 Jupyter 笔记本看到的路径与 env 命令行中显示的路径不同的事实。我该如何解决?

标签: python-3.xamazon-web-servicespipaws-cli

解决方案


首先介绍一下我的环境的背景:

我在 ubuntu 机器上安装了 aws

pip install aws

我检查了终端中的以下命令

aws

给了我输出:

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters] To see help text, you can run:

  aws help   aws <command> help   aws <command> <subcommand> help aws: error: the following arguments are required: command

正如预期的那样。我还想知道需要注册哪条路径才能找到aws。因此,我输入:

which aws

这给了我

/usr/bin/aws

然后我启动了一个 docker 容器,并在其中启动了一个 jupyter notebook 实例。我也将 /usr/bin 路径映射到 /usr/bin 。在 jupyter 笔记本中,我想确定是否可以访问 /usr/bin/aws。我试过了:

!ls /usr/bin/aws

但什么也没找到。我仍然认为这很奇怪而且我不明白,因为我可以找到该文件夹​​的其余部分。正如预期的那样,在 jupyter 中输入“!aws”给了我一个“找不到命令”。

现在这里也应该解决您的问题的部分:

在您的 jupyter 环境中安装 awscli,就像我一样,它可能与您成功运行 aws 命令的环境不同。在 jupyter 中运行:

!pip install awscli

我之前在终端中配置过aws。然而在 jupyter 中(在 docker 中),配置是空的。我按照官方教程连接到 docker 容器并运行“aws configure”。如果您不运行 docker,而是运行 anaconda 或任何虚拟环境,则需要进入此环境,然后 pip install aws 并在那里运行 aws configure。

一旦你这样做了,在你的 jupyter notebook 中输入“!aws”应该会给你预期的输出

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters] To see help text, you can run:

  aws help   aws <command> help   aws <command> <subcommand> help aws: error: the following arguments are required: command

希望这可以帮助。


推荐阅读