简体   繁体   English

pip:找不到命令

[英]pip: command not found

I encounter a problem when installing pip for python2.7. 在为python2.7安装pip时遇到问题。 I downloaded the file get-pip.py, and install it successfully: 我下载了文件get-pip.py,并成功安装了它:

bogon:haha itensb$ python get-pip.py
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages
Cleaning up...

But when I run the command pip, I got: 但是当我运行命令pip时,我得到了:

-bash: pip: command not found

I think it is the PATH not set appropriatelly , But I new on Mac. 我认为这是未适当设置的PATH,但是我在Mac上是新的。 I need your help , thanks! 我需要你的帮助,谢谢!

Use python -m pip . 使用python -m pip If you want the pip command check out @user3282276's answer. 如果要使用pip命令,请查看@ user3282276的答案。

Sounds like your PATH variable is not set to include the location that pip was installed to. 听起来您的PATH变量未设置为包含pip的安装位置。 On Macs and other *nix like operating systems when you type a command in the command line, what is actually happening is the shell is trying to find the executable file in a predefined area, called the PATH variable. 在Mac和其他* nix操作系统上,当您在命令行中键入命令时,实际上正在发生的情况是Shell试图在预定义区域(称为PATH变量)中查找可执行文件。 If you are interested check out this question, https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them . 如果您有兴趣,请查看此问题, https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

You are able to see what yours is set to if you do this in your command line 如果您在命令行中执行此操作,则可以看到您的设置

echo $PATH

this will give you some file paths separated by colons, for example when I type the command above I get this: 这将为您提供一些用冒号分隔的文件路径,例如,当我在上面键入命令时,我得到以下信息:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Applications/Android Dev Tool/sdk/tools

which means that my shell will check for a executable in each of these files, if it finds it, it will run otherwise it will tell you the program can't be found. 这意味着我的shell将在每个文件中检查可执行文件,如果找到它,它将运行,否则它将告诉您找不到该程序。 As a side note this is the reason why when you run an executable not in one of these PATH files you must do, 附带说明,这就是为什么当您不在这些PATH文件之一中运行可执行文件时必须这样做的原因,

./program

this is specifying a relative path to the executable file, the current directory that you are in. 这是指定可执行文件(您当前所在的目录)的相对路径。

So for you, you installed pip to this directory: 因此,对于您来说,您将pip安装到了以下目录:

/Library/Python/2.7/site-packages

chances are the above echo statement did not include this file, if it did then you have another problem. 上面的echo语句很可能不包含此文件,如果包含,则您有另一个问题。 What you need to do is to update your PATH variable to include this directory as well. 您需要做的就是更新PATH变量,使其也包含此目录。 To do this you add an export statement to your .bash_profile (or .bashrc on Linux) in your home directory (this is a hidden file) that includes your current path variables (so you will still be able to run everything installed in the proper place) and this new directory that you installed pip to. 为此,您需要在主目录(这是一个隐藏文件)中的.bash_profile (或Linux中的.bashrc )中添加一个导出语句,该语句包含当前路径变量(因此,您仍然可以运行正确安装的所有文件)位置)和安装pip的新目录。 To do this add this line to the end of your .bash_profile 为此,请将此行添加到.bash_profile的末尾

export PATH=${PATH}:/Library/Python/2.7/site-packages

and you should be good to go. 而且你应该很好走。 However before it will take effect you need to close and open your terminal window again or run source .bash_profile . 但是,在生效之前,您需要再次关闭并打开终端窗口或运行source .bash_profile You can verify this worked by running the echo command above, it should return the same thing but this time with /Library/Python/2.7/site-packages appended to the end. 您可以通过运行上面的echo命令来验证此方法是否有效,但是它应该返回相同的内容,但是这次将/Library/Python/2.7/site-packages附加到末尾。

Note: By the way the which command that you were told to run in the comments locates a program within the users path, which is why it did not return anything to you. 注:顺便说which命令,你被告知要在评论中运行用户路径,这就是为什么它没有什么回报给你内定位的程序。 Also since you will probably run into this soon enough there is also a variable called PYTHONPATH (look here ) which tells python where to look to import modules. 另外,由于您可能很快就会遇到这种情况,因此还有一个名为PYTHONPATH的变量(请PYTHONPATH 此处 ),它告诉python在哪里导入模块。 You should set this to whatever directory you have pip installing modules to if it is not already set. 如果尚未设置pip安装模块的目录,则应将其设置为该目录。

Install python3 first, then use pip3 to install packages. 首先安装python3,然后使用pip3安装软件包。

brew install python brew安装python

python3 will be installed, and pip is shipped with it. 将会安装python3,并且pip附带了它。 To use pip to install some package, run the following 要使用pip安装一些软件包,请运行以下命令

pip3 install package pip3安装包

Notice it's pip3 because you want to use python3. 注意它是pip3,因为您想使用python3。

My same answer here 在这里的相同答案

运行命令,它的工作原理

sudo easy_install pip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM