Python 使用pip安装nose,但bash无法识别mac上的命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18796988/
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 11:53:15  来源:igfitidea点击:

Installing nose using pip, but bash doesn't recognize command on mac

pythonpython-2.7nosepython-modulenosetests

提问by Zubin

I'm trying to install nose on my computer for the Learn Python the Hard Way tutorial, but can't seem to get it to work. I'm using pip to install:

我正在尝试在我的计算机上为 Learn Python the Hard Way 教程安装鼻子,但似乎无法让它工作。我正在使用 pip 安装:

$ pip install nose

And I get back:

我回来了:

Requirement already satisfied (use --upgrade to upgrade): nose in /usr/local/lib/python2.7/site-packages
Cleaning up...

However, when I run the command nosetests, I get:

但是,当我运行命令nosetests时,我得到:

-bash: nosetests: command not found

I'm thinking there's something wrong with my PATH, but honestly I have no idea. Any help would be greatly appreciated!

我在想我的 PATH 有问题,但老实说我不知道​​。任何帮助将不胜感激!

回答by 7stud

However, when I run the command nosetests,

然而,当我运行命令nosetests时,

Of course, how you ran that command and from what directory might be important.

当然,您如何运行该命令以及从哪个目录运行可能很重要。

I'm thinking there's something wrong with my PATH, but honestly I have no idea.

我在想我的 PATH 有问题,但老实说我不知道​​。

If you do:

如果你这样做:

$ echo $PATH

...you will be able to see all the directories in your path. Of course, you can add any directory you want to your PATH.

...您将能够看到路径中的所有目录。当然,您可以将任何您想要的目录添加到您的 PATH 中。

However, I recently installed nose on my mac, and I installed by hand:

不过,我最近在我的 mac 上安装了nose,我手动安装了:

.../Downloads$ tar xfvz nose-1.3.0
.../Downlaods$ cd nose-1.3.0
.../nose-1.3.0$ sudo python setup.py install

...and nosetests installed here:

...和这里安装的鼻子测试:

$ which nosetests
/Library/Frameworks/Python.framework/Versions/2.7/bin/nosetests

And there is a nose directory in my site-packages directory as per usual, as well. So on my mac, nosetests installed in a directory outside the site-packages directory. It's possible that only newer versions of nose install the nosetests command. You might want to try:

和往常一样,我的站点包目录中也有一个鼻子目录。所以在我的 mac 上,nosetests 安装在 site-packages 目录之外的目录中。可能只有较新版本的nose 才安装nosetests 命令。您可能想尝试:

$ pip install --upgrade nose

回答by Edgar Aroutiounian

pigging backing off of 7stud, you could do sudo find / -name nosetestsand then append that to your PATH

背靠 7stud,你可以这样做sudo find / -name nosetests,然后将它附加到你的PATH

(I'm sure that doing findoff of /is a bit overkill, but I like that it goes over the entire OS)

(我敢肯定,这样做find的关闭/是有点大材小用,但我喜欢它越过整个OS)

回答by Maxim Yefremov

I got this problem until I setup nose with sudo:

我遇到了这个问题,直到我设置了鼻子sudo

sudo pip install nose

回答by Tossrock

On OSX, using pip to install nose 1.3 installed nose to /usr/local/share/python/nosetests which isn't in the $PATH by default.

在OSX 上,使用pip 安装nose 1.3 安装nose 到/usr/local/share/python/nosetests,默认情况下它不在$PATH 中。

回答by Chris

I know this is an old thread but just in case someone else needs it:

我知道这是一个旧线程,但以防万一其他人需要它:

I'm using OS X 10.9.3. After installing all of the packages 'cd' into the project directory as instructed in the book. Then type

我使用的是 OS X 10.9.3。按照书中的说明将所有软件包“cd”安装到项目目录中后。然后输入

sudo nosetests

Then you'll see what the 'learnpythonthehardway' author shows in the book and online.

然后,您将看到“learnpythonthehardway”作者在书中和在线展示的内容。

回答by Raphael

I'm using OS X 10.11.1.

我使用的是 OS X 10.11.1。

Do the following in the terminal:

在终端中执行以下操作:

  1. Move into directory ~/Python/2.7/site-packages/

  2. type sudo easy_install pip

  3. type sudo easy_install virtualenv

  4. type sudo easy_install nose

  5. type sudo easy_install distribute

  6. Follow the steps as instructed in the Learn Python The Hard Waybook.

  1. 进入目录 ~/Python/2.7/site-packages/

  2. 类型 sudo easy_install pip

  3. 类型 sudo easy_install virtualenv

  4. 类型 sudo easy_install nose

  5. 类型 sudo easy_install distribute

  6. 按照Learn Python The Hard Way一书中的说明执行步骤。

回答by Dennis

You can reinstall using apt-get -y install python-nose.

您可以使用apt-get -y install python-nose.

回答by Jimmy_Rw

i had the same problem but this solved it.

我有同样的问题,但这解决了它。

  1. Install: nose2
  2. Then use: nose2instead of noseteststo test program
  1. 安装: 鼻子2
  2. 然后使用:nose2代替nosetests来测试程序

Good Luck...!

祝你好运...!

回答by Quang Nguyen

Setting PATH variable for 'nosetests' is required. Please use this one on your Terminal:

需要为 'nosetests' 设置 PATH 变量。请在您的终端上使用这个:

alias nosetests='/Library/Frameworks/Python.framework/Versions/2.7/bin/nosetests'

alias nosetests='/Library/Frameworks/Python.framework/Versions/2.7/bin/nosetests'

Good luck!

祝你好运!

回答by Nathan Smith

Sorry for resurrecting an old thread, but I just want to point out that no one has mentioned activating the virtual environment. People are asking "Are you in the virtual environment?" but user2778157seems to be confused on exactly what that means. I would like to clarify this and think it may actually be the source of the problem. (Sorry for the pun on source).

抱歉复活了一个旧线程,但我只想指出没有人提到激活虚拟环境。人们问“你在虚拟环境中吗?” 但user2778157似乎对这到底意味着什么感到困惑。我想澄清这一点,并认为它实际上可能是问题的根源。(抱歉对源头的双关语)。

When you use pip install, you aren't installing to your host's system, but into the virtual environment. When you create a virtual environment, it will have a folder binwith a file activatein it. In order to activate the virtual environment, you need to do source PATH/TO/ACTIVATE. While your virtual environment is activated, your system will check your virtual environment for the program before checking the host, and this is where your pip packages should be.

当您使用 时pip install,您不是安装到主机系统,而是安装到虚拟环境中。创建虚拟环境时,它将有一个文件夹,bin其中包含一个文件activate。为了激活虚拟环境,您需要执行source PATH/TO/ACTIVATE. 当您的虚拟环境被激活时,您的系统会在检查主机之前检查您的程序的虚拟环境,这就是您的 pip 包应该在的地方。

The reason you don't use sudo pip installis because this will get the super user (who doesn't have the environment activated) to install the package, which will go to your host.

你不使用的原因sudo pip install是因为这将让超级用户(没有激活环境)安装软件包,该软件包将转到您的主机。