代码之家  ›  专栏  ›  技术社区  ›  AdjunctProfessorFalcon

已安装Nose,但无法在命令行上使用

  •  20
  • AdjunctProfessorFalcon  · 技术社区  · 9 年前

    我使用Python2.7.9在Mac OSX 10.10.5上安装了Nose easy_install 。安装似乎成功:

    Collecting nose
      Downloading nose-1.3.7-py2-none-any.whl (154kB)
        100% |████████████████████████████████| 155kB 2.3MB/s 
    Installing collected packages: nose
    Successfully installed nose-1.3.7
    

    但现在,当我在命令行上尝试使用鼻测试的基本功能时,比如 nosetests -h which nosetests 我只得到:

    bash: nosetests: command not found
    

    我已尝试卸载,使用重新安装 pip ,尝试使用安装 sudo 然后运行 sudo nostests 正如其他帖子所建议的那样,在包含测试脚本的目录中,但似乎没有任何效果。

    安装的最初目的是使用nose运行一些基本测试,这些测试脚本是我为这些简单的web编写的。py应用程序。但什么都没用,只要继续 command not found 回答

    奇怪的是,当我在终端中打开Python解释器,并执行以下操作时:

    import nose 
    nose.main()
    

    我得到的预期结果是:

    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.135s
    
    OK
    

    很明显,它安装在某个地方。对这里到底发生了什么有什么建议吗?

    9 回复  |  直到 9 年前
        1
  •  29
  •   yolanda.ly    8 年前

    使用时出现很多错误 pip 在Mac OS上安装软件包。所以我建议您安装 nose 使用 easy_install .

    $ pip uninstall nose

    $ sudo easy_install nose

    那你可以试试 nosetests 现在:)

        2
  •  15
  •   mx0 aleclara95    7 年前

    我在Python 2.7.10的OS X EI Captain上遇到了这个问题。

    第一次安装 使用 :

    $sudo pip install nose 
    

    第一次尝试失败。第二次尝试成功了。但是 nosetests 命令不起作用。

    为了解决此问题:

    步骤1:不卸载 如果已使用安装 就像我的情况一样。

    第2步:

    $cd /usr/bin
    
    $sudo easy_install nose 
    

    上面的命令查找nosetests脚本(由pip先前安装)&将其置于 /usr/local/bin

    Step 3: Try nosetests
    
    $nosetests
    
    ----------------------------------------------------------------------
    Ran 0 tests in 0.047s
    
    OK
    
        3
  •  12
  •   Roland Smith    9 年前

    在类UNIX系统(如OS X)上,脚本 应该 /usr/local/bin 。确保该目录位于 PATH 您使用的shell中的环境变量。

    如果没有,也可以使用 find ,例如:

    find / -type f -name 'nosetests*' -perm +111 -print -quit
    

    这意味着:;搜索名称以开头的文件 nosetests ,已设置执行权限。打印路径名并停止。

        4
  •  3
  •   Jacob Herold    9 年前

    我发现

    Library/usr/bin 
    

    和正在运行

    sudo easy_install nose
    

    它似乎有时不会自动安装nose(因此也不会自动安装鼻测试功能)。做以上几行,你会没事的。

    我希望我能更好地解释为什么会发生这种情况,但我自己还是个新手。

        5
  •  1
  •   Lorenz    3 年前

    我不得不使用

    Nosetest
    

    python3 -m "nose"
    

    显然,这就是在Python3中使用Nosetest的方式 How to make nosetests use python3

        6
  •  0
  •   Rich L    9 年前

    首先,您可以从命令行运行“python”吗?nosetests应该在同一目录中:

    rich bin $ which python
    /home/rich/anaconda/bin/python
    rich bin $ which nosetests
    /home/rich/anaconda/bin/nosetests
    

    它也应该在下载的nose包中:

    rich bin $ find /home/rich/anaconda -name nosetests
    /home/rich/anaconda/pkgs/nose-1.3.3-py27_0/bin/nosetests
    /home/rich/anaconda/pkgs/nose-1.3.7-py27_0/bin/nosetests
    /home/rich/anaconda/bin/nosetests
    
        7
  •  0
  •   Boris Yakubchik    6 年前

    据我所知,每个人都在向 pytest -一个积极维护的测试框架。

    这不是解决方案 问题,但如果您仍在使用,这可能是最合适的选择 .

        8
  •  0
  •   Community CDub    4 年前

    我尝试重新安装pip,它不起作用,但最后,当我使用sudo时…它起作用

    pip3卸载鼻子

    sudo pip3安装鼻端

    哪些鼻测试

    /usr/local/bin/nosetests

        9
  •  0
  •   Neil Murphy    6 年前

    如果您在虚拟环境中运行nose,并且该虚拟环境已被停用,则也可能发生这种情况。如果是这种情况,请使用重新激活 source bin/activate .