Python awscli 安装后未添加到路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23332147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:46:27  来源:igfitidea点击:

awscli not added to path after installation

pythonmacosamazon-web-servicespip

提问by Max

I installed the aws cli according to the offical Amazon directions.

我根据亚马逊的官方说明安装了 aws cli。

sudo pip install awscli

However, awsis nowhere to be found in my path. The installation seems to have been successful. There are a number of files located at /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/awscli, however there are no executables named aws. My python version is 3.3.4, my pip version is 1.5.4, and running this command on OS X 10.9. What could be wrong?

然而,aws在我的道路上无处可寻。安装似乎已经成功。有许多文件位于/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/awscli,但是没有名为 的可执行文件aws。我的python版本是3.3.4,我的pip版本是1.5.4,在OS X 10.9上运行这个命令。可能有什么问题?

Thanks!

谢谢!

采纳答案by Bruno Bronosky

Improving the OP's Answer

改进 OP 的答案

The OP answered their own question, but the exact location of the executable is more likely to be different than it is to be the same. So, let's break down WHY his solution worked so you can apply it to yourself.

OP 回答了他们自己的问题,但可执行文件的确切位置更有可能与其相同。因此,让我们分解为什么他的解决方案有效,以便您可以将其应用于自己。

From the problem

从问题

There are a number of files located at /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/awscli, however there are no executables named aws.

有许多文件位于/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/awscli,但是没有名为 aws 的可执行文件。

From the solution

解决方案

The solution was to add /Library/Frameworks/Python.framework/Versions/3.3/binto the my PATH.

解决方案是添加/Library/Frameworks/Python.framework/Versions/3.3/bin到我的路径。

Let's learn something

让我们学点东西

Compare those paths to find their commonality:

比较这些路径以找到它们的共同点:

/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/awscli
/Library/Frameworks/Python.framework/Versions/3.3/bin

Notice that they diverge at libvs. bin. And consider that the OP stated, "there are no executables named aws." That brings us to our first learning lessons:

请注意,它们在libvs. 处发散bin。并考虑到 OP 声明,“没有名为 aws 的可执行文件。”这将我们带到了我们的第一个学习课程:

  • Executables tend to not be in libfolders.
  • Look for binfolders that share a common lineage.
  • 可执行文件往往不在lib文件夹中。
  • 查找bin共享共同谱系的文件夹。

In this case I would have suggested looking for binfolders via:

在这种情况下,我会建议bin通过以下方式查找文件夹:

find /Library/Frameworks/Python.framework -type d -name bin

But, if you are going to do that, you might as well just search for your executable via:

但是,如果您打算这样做,您不妨通过以下方式搜索您的可执行文件:

find /Library/Frameworks/Python.framework -type f -perm -100 -name aws
# the `-` in `perm -100` means not an exact match of 100
# but any octal that includes 100

But wait

可是等等

How did OP know to look in their /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/?

OP怎么知道看他们的/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/

The easiest answer is also our next learning lesson:

最简单的答案也是我们的下一个学习课程:

  • Ask your python where things are installed.
  • 询问你的 python 东西安装在哪里。

Here is how I do that:

这是我如何做到的:

$ python -c 'import awscli; print(awscli)'
<module 'awscli' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/awscli/__init__.pyc'>

$ python3 -c 'import awscli; print(awscli)'
<module 'awscli' from '/System/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/awscli/__init__.py'>

I have 2 Pythons and neither of them use the same paths or even path patterns as the OP.

我有 2 个 Python,它们都没有使用与 OP 相同的路径甚至路径模式。

Apply what we've learned

应用我们学到的

$ find /System/Library/Frameworks/Python.framework -type d -name bin
/System/Library/Frameworks/Python.framework/Versions/2.7/bin
/System/Library/Frameworks/Python.framework/Versions/3.6/bin

$ find /System/Library/Frameworks/Python.framework -type f -perm -100 -name aws
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/aws
/System/Library/Frameworks/Python.framework/Versions/3.6/bin/aws

As you can see, I have 2 binfolders and 2 awsexecutables. I probably want to use the Python3.6 version. However, if I'm doing local trial and error work for a remote system that uses the Python2.7 version, I'm going to want to use that. And this is exactly why I have 2 version installed.

如您所见,我有 2 个bin文件夹和 2 个aws可执行文件。我可能想使用 Python3.6 版本。但是,如果我正在为使用 Python2.7 版本的远程系统进行本地试错工作,我会想要使用它。这正是我安装 2 个版本的原因。

回答by Max

The solution was to add

解决方案是添加

/Library/Frameworks/Python.framework/Versions/3.3/bin

to the my PATH.

到我的路径。

回答by Bill Mitchell

I upgraded from OSX 10.7 to OSX 10.9 and afterwards, my installation of aws no longer worked.

我从 OSX 10.7 升级到 OSX 10.9 之后,我的 aws 安装不再有效。

I observed errors like this:

我观察到这样的错误:

$ pip
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: pip==1.5.5

The solution that the operating system upgrade had changed permissions.

操作系统升级修改权限的解决方法。

Giveaway clue:

赠品线索:

sudo pip <--- worked

须藤点<---工作

pip <--- failed

pip <--- 失败

So I did this:

所以我这样做了:

sudo chmod -R a+r /Library/Python/

and then afterwards, I'm able to use the aws commands again.

然后,我可以再次使用 aws 命令。

Not sure if this is something that will be helpful for others, but figured I'd throw it into the mix.

不确定这是否对其他人有帮助,但我想我会把它扔进去。

回答by Scott Lawton

When installing in a virtualenv: 'pip install awscli' (without sudo) worked fine on OS X; but not on CentOS release 6.6, e.g. 'which aws' found nothing. The solution:

在 virtualenv 中安装时:“pip install awscli”(不带 sudo)在 OS X 上运行良好;但不是在 CentOS 版本 6.6 上,例如“which aws”一无所获。解决方案:

chmod u+x /PATH-TO-YOUR-VIRTUALENV/bin/aws

回答by BRass

Windows is likely the minority here, but adding below to my PATH worked for me. For reference, I installed the CLI via pip:

Windows 可能是这里的少数,但将下面添加到我的 PATH 对我有用。作为参考,我通过 pip 安装了 CLI:

C:\Python27\Scripts

回答by Bruno Bronosky

From http://docs.aws.amazon.com/cli/latest/userguide/cli-install-macos.html#awscli-install-osx-path

来自http://docs.aws.amazon.com/cli/latest/userguide/cli-install-macos.html#awscli-install-osx-path

For Modern macos/OSX, you need to find your ~/Library/Python/$version/bindirectory and add it to your $PATH. This will help you locate the one where awsgot installed.

对于 Modern macos/OSX,您需要找到您的~/Library/Python/$version/bin目录并将其添加到您的$PATH. 这将帮助您找到aws已安装的那个。

$ ls -d ~/Library/Python/*/bin/aws
/Users/bbronosky/Library/Python/3.6/bin/aws

So based on that I added this line to my .bashrc

所以基于此,我将此行添加到我的 .bashrc

export PATH=$HOME/Library/Python/3.6/bin:$PATH

回答by Govind Rai

Edit the pathsfile directly if you have admin rights.

paths如果您具有管理员权限,则直接编辑该文件。

Definitely go with the top answer if you don't have admin rights, but if you do then I would highly recommend directly editing the pathsfiles, located at /etc/paths.

如果您没有管理员权限,请务必使用最佳答案,但如果您有管理员权限,我强烈建议您直接编辑paths位于/etc/paths.

Use your favorite editor and simply paste the desired path on a new line:

使用您最喜欢的编辑器并将所需的路径粘贴到新行上:

Sample pathsfile:

示例paths文件:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Users/username/Library/Python/3.6/bin #new path added here at bottom of file

Paste at the top or bottom or in whatever order you would like the locations searched for binaries (in the event there are binaries with duplicate names).

粘贴在顶部或底部或以您希望搜索二进制文件的位置的任何顺序粘贴(如果存在具有重复名称的二进制文件)。

Using the pathsfile saves you the hassle of remembering the concatenation syntax or the potential trouble if you write an faulty export statement.

使用该paths文件可以省去记住串联语法的麻烦,或者在编写错误的导出语句时避免潜在的麻烦。

回答by dheeraj .A

This worked for me on mac:

这在 mac 上对我有用:

sudo -H pip install awscli --upgrade --ignore-installed six

回答by Proximo

What I typically do is copy the executable to /usr/local/bin

我通常做的是将可执行文件复制到/usr/local/bin

cp $(find / -name aws) /usr/local/bin

回答by kmahankali

I had a similar problem on windows 10. I had to add below to PATHvariables

我在 Windows 10 上遇到了类似的问题。我必须在下面添加PATH变量

For Python:

对于Python

C:\Users\kumar\AppData\Local\Programs\Python\Python37\  

For PIP:

对于画中画

C:\Users\kumar\AppData\Local\Programs\Python\Python37\Scripts\

For awsclito work:

为了awscli工作:

C:\Users\kumar\AppData\Roaming\Python\Python37\Scripts