已安装 Nose 但无法在命令行上使用
Installed Nose but cannot use on command line
我在 Mac OSX 10.10.5 和 Python2.7.9 使用 easy_install
安装了 Nose。安装似乎成功:
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 尝试基本的东西时,比如 nosetests -h
或 which nosetests
我只是得到:
bash: nosetests: command not found
我尝试卸载,使用 pip
重新安装,尝试使用 sudo
安装,然后 运行ning sudo nostests
在目录中使用测试脚本,正如其他帖子所建议的, 但似乎没有任何效果。
安装的最初目的是使用 nose 运行 一些基本测试以及我为这些简单的 web.py 应用程序编写的测试脚本。但没有任何效果,只是不断收到 command not found
响应。
奇怪的是,当我在终端中打开 Python 解释器并执行如下操作时:
import nose
nose.main()
我得到了预期的结果:
.
----------------------------------------------------------------------
Ran 1 test in 0.135s
OK
很明显它已安装....某处。对这里到底发生了什么有什么建议吗?
首先,您可以从命令行 运行 '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
在像 OS X 这样的类 UNIX 系统上,脚本 应该 在 /usr/local/bin
中。确保该目录位于您使用的 shell 中的 PATH
环境变量中。
如果没有,您也可以使用find
定位,例如:
find / -type f -name 'nosetests*' -perm +111 -print -quit
这意味着;搜索名称以 nosetests
开头的文件,该文件设置了执行权限。打印路径名并停止。
我发现要去
Library/usr/bin
和运行
sudo easy_install nose
似乎有时它不会自动安装 nose(因此不会自动安装 nosetests 功能)。执行以上几行,你应该a-ok。
我希望我能更好地解释为什么会这样,但我自己还是个新手。
在 Mac OS 上使用 pip
安装包时出现很多错误。所以我建议您使用 easy_install
安装 nose
。
$ pip uninstall nose
$ sudo easy_install nose
那你现在可以试试nosetests
:)
我在 OS X EI Captain with Python 2.7.10.
上遇到了这个问题
首先我使用 pip 安装了 nose:
$sudo pip install nose
第一次尝试失败。第二次尝试通过。但是 nosetests
命令不起作用。
为了解决这个问题:
第 1 步:如果已经使用 pip 安装了 nose,请不要卸载 nose。
第 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
据我了解,每个人都在转向 pytest - 一个积极维护的测试框架。
这不是这个问题的解决方案,但如果您仍在使用nose,它可能是最合适的选择。
我尝试重新安装 pip,它不起作用,但最后,当我使用 sudo 时......它起作用了
pip3 uninstall nose
sudo pip3 install nose
和
which nosetests
/usr/local/bin/nosetests
如果您 运行 进入虚拟环境并且该虚拟环境已停用,也会发生这种情况。如果是这种情况,请使用 source bin/activate
.
重新激活
我不得不使用
Nosetest
或
python3 -m "nose"
显然这就是 Nosetest 在 Python3 中的使用方式。也可以看看
How to make nosetests use python3
我在 Mac OSX 10.10.5 和 Python2.7.9 使用 easy_install
安装了 Nose。安装似乎成功:
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 尝试基本的东西时,比如 nosetests -h
或 which nosetests
我只是得到:
bash: nosetests: command not found
我尝试卸载,使用 pip
重新安装,尝试使用 sudo
安装,然后 运行ning sudo nostests
在目录中使用测试脚本,正如其他帖子所建议的, 但似乎没有任何效果。
安装的最初目的是使用 nose 运行 一些基本测试以及我为这些简单的 web.py 应用程序编写的测试脚本。但没有任何效果,只是不断收到 command not found
响应。
奇怪的是,当我在终端中打开 Python 解释器并执行如下操作时:
import nose
nose.main()
我得到了预期的结果:
.
----------------------------------------------------------------------
Ran 1 test in 0.135s
OK
很明显它已安装....某处。对这里到底发生了什么有什么建议吗?
首先,您可以从命令行 运行 '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
在像 OS X 这样的类 UNIX 系统上,脚本 应该 在 /usr/local/bin
中。确保该目录位于您使用的 shell 中的 PATH
环境变量中。
如果没有,您也可以使用find
定位,例如:
find / -type f -name 'nosetests*' -perm +111 -print -quit
这意味着;搜索名称以 nosetests
开头的文件,该文件设置了执行权限。打印路径名并停止。
我发现要去
Library/usr/bin
和运行
sudo easy_install nose
似乎有时它不会自动安装 nose(因此不会自动安装 nosetests 功能)。执行以上几行,你应该a-ok。
我希望我能更好地解释为什么会这样,但我自己还是个新手。
在 Mac OS 上使用 pip
安装包时出现很多错误。所以我建议您使用 easy_install
安装 nose
。
$ pip uninstall nose
$ sudo easy_install nose
那你现在可以试试nosetests
:)
我在 OS X EI Captain with Python 2.7.10.
上遇到了这个问题首先我使用 pip 安装了 nose:
$sudo pip install nose
第一次尝试失败。第二次尝试通过。但是 nosetests
命令不起作用。
为了解决这个问题:
第 1 步:如果已经使用 pip 安装了 nose,请不要卸载 nose。
第 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
据我了解,每个人都在转向 pytest - 一个积极维护的测试框架。
这不是这个问题的解决方案,但如果您仍在使用nose,它可能是最合适的选择。
我尝试重新安装 pip,它不起作用,但最后,当我使用 sudo 时......它起作用了
pip3 uninstall nose
sudo pip3 install nose
和
which nosetests
/usr/local/bin/nosetests
如果您 运行 进入虚拟环境并且该虚拟环境已停用,也会发生这种情况。如果是这种情况,请使用 source bin/activate
.
我不得不使用
Nosetest
或
python3 -m "nose"
显然这就是 Nosetest 在 Python3 中的使用方式。也可以看看 How to make nosetests use python3