关于终端:找不到py.test命令,但已安装库

Py.test command not found, but library is installed

关于该主题的堆栈溢出已经有两篇文章。 但是,他们都没有解决或解决我的具体情况。

我已经通过pip install pytest安装了pytest。 我也可以用Python导入该库。

问题是,当我尝试在终端中使用py.test命令时,得到了py.test: command not found

是否有人对我为什么无法在终端中使用该命令有任何见解?

编辑:它甚至显示为已安装的软件包:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ pip list
cycler (0.9.0)
matplotlib (1.5.1)
numpy (1.10.1)
pip (8.1.0)
py (1.4.31)
pyparsing (2.0.7)
pytest (2.9.0)
python-dateutil (2.4.2)
pytz (2015.7)
scipy (0.17.0)
setuptools (7.0)
six (1.10.0)
tensorflow (0.5.0)
vboxapi (1.0)
wheel (0.26.0)


使用python -m pytest将为您工作。

或者,如果您使用虚拟环境并在virtualenv上安装了pytest,则应在虚拟环境旁边运行py.test。

检查此网站是否有用:http://pythontesting.net/framework/pytest/pytest-introduction/


您是否有机会尝试自制Mac?

我有同样的问题,它基本上归结为权限/与mac os base安装的python冲突。 pip install无法安装或链接东西到/ usr / local / bin(virtualenv和pytest都发生了)。

  • 我使用自制软件(brew uninstall python)完全卸载了python 2.7。
  • 接下来,我用自制软件重新安装了python以修复pip(它不是/ usr / local / bin / pip中的符号链接,它应该已经链接到Cellar了)-brew install python
  • 然后我用sudo-sudo python -m pip uninstall pip卸载了pip以删除root拥有的pip
  • 现在,我再次使用homebrew卸载并重新安装了python,以正确的权限重新安装pip brew uninstall python && brew install python
  • 接下来,我修复了python符号链接brew link python
  • 最后,pip install pytest起作用了! (pip install virtualenv也是如此)
  • 我发现从这篇文章中选择的答案中的信息非常有帮助:
    https://superuser.com/questions/915810/pip-not-working-on-hombrew-python-2-7-install。

    如果您不在Mac电脑上,请多多包涵...


    我已经在装有Homebrew的Python 2.7的macOS上安装了最新版本的pytest,并对此进行了修复:

    1
    2
    pip uninstall pytest
    pip install pytest

    我可能来晚了,但是在探索这一点时,我注意到这可能是因为PATH中不存在python的Scripts文件夹。

    对我来说,这是我的脚本文件夹:

    1
    C:\Python38\Scripts\

    如果路径有问题,那么实际上运行pip install pytest应该给您警告,并添加该路径。

    这应该出现在路径中。如果在Windows上,将环境变量和此位置编辑到PATH。

    对我来说,路径错误是因为python安装不正确


    我通过以下步骤解决了此问题。
    1.首先卸载现有的pytest。
    2.检查python版本。
    3.然后通过github问题跟踪器验证python版本是否支持pytest版本。
    4.通过sudo install pytest
    sudo pip安装pytest
    5.验证pytest版本和是否正确安装。
    点列表
    pytest-版本

    6,使用pytest test_abc.py运行任何测试


    我遇到过同样的问题。我安装了pytest v2.8.3,二进制文件在我的路径上,但名为py.test。升级到v3.0.3会将常规pytest可执行文件添加到该路径。