简体   繁体   English

在 MAC OS X 上,py.test 未被识别为命令

[英]on MAC OS X, py.test not recognized as a command

On MAC OS X 10.10;在 MAC OS X 10.10 上; I installed pytest 2.6.4;我安装了pytest 2.6.4; however in Terminal If I write py.test or even py.test --version;但是在终端如果我写 py.test 甚至 py.test --version; I get the error:我收到错误:

-bash: py.test command not found

(a) Am I missing anything? (a) 我错过了什么吗? What do I do to make the pytest tool recognizable.我该怎么做才能使 pytest 工具可识别。 I searched alot;我搜索了很多; but couldn't find any info except http://teckla.idyll.org/~t/transfer/py.test.html但除了http://teckla.idyll.org/~t/transfer/py.test.html之外找不到任何信息

I checked in the PyCharm preferences, I don't see py.test interpreter listed there.我检查了 PyCharm 首选项,我没有看到那里列出了 py.test 解释器。 However, pip freeze displays pytest 2.6.4 installed.但是,pip freeze 显示已安装 pytest 2.6.4。

(b) Is PYTHONPATH required to be set on MAC? (b) 是否需要在 MAC 上设置 PYTHONPATH? Although I've seen setting it is not required on Windows.尽管我已经看到在 Windows 上不需要设置它。

Appreciate any pointers to help me resolve this.感谢任何帮助我解决这个问题的指针。


Update: Contents of my bash_profile:更新:我的 bash_profile 的内容:

echo export PATH="HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
PATH="/Users/admin/Library/Python/2.7/lib/python/site-packages:$PATH"
PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH"
export PATH

On OS X you should do:在 OS X 上你应该这样做:

pip install -U pytest 

or或者

easy_install -U pytest

http://pytest.org/latest/getting-started.html http://pytest.org/latest/getting-started.html

For those of us trying to avoid any and all use of sudo :对于我们这些试图避免任何和所有使用sudo

  1. Download from PyPI here and unpack.从此处从 PyPI 下载并解压缩。
  2. $ cd <pytest download folder>
  3. $python setup.py build
  4. $python setup.py install --user
  5. Wherever the installing output says the "py.test script" has been installed to, add to PATH in your .bash_profile (or .bashrc if you use that for environment variables).无论安装输出显示“py.test 脚本”已安装到何处,都将其添加到 .bash_profile(或 .bashrc,如果您将其用于环境变量)中的PATH
  6. Confirm the setup worked via $py.test --version通过$py.test --version确认设置有效

Got it worked finally!终于搞定了! After downloading pytest, I ran the following commands and it worked like magic.下载 pytest 后,我​​运行了以下命令,它就像魔术一样工作。 I think,earlier, I missed putting "sudo" infront of the install command:我想,早些时候,我错过了在安装命令前面放置“sudo”:

$python setup.py build
$sudo python setup.py install

The output said:输出说:

..
Installing py.test script to /usr/local/bin
Installing py.test-2.7 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pytest-2.6.4-py2.7.egg
..
Using /Users/admin/Library/Python/2.7/lib/python/site-packages
Finished processing dependencies for pytest==2.6.4

My .bash_profile contents, jfyr:我的 .bash_profile 内容,jfyr:

PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/System/Library/Frameworks/Python.framework/Versions/2.7/bin"
export PATH

pip3 install -U pytest 使用 Python 3.7 版本

I had a problem installing pytest on Mac M1 but I followed the python pip documentation and it worked.我在 Mac M1 上安装 pytest 时遇到问题,但我遵循了 python pip 文档并且它工作正常。 What i did was:我所做的是:

  • istalled pip via command in Pycharm terminal (I use pycharm): python3 -m pip install pytest通过 Pycharm 终端中的命令安装 pip(我使用 pycharm):python3 -m pip install pytest

  • after installation I run the pytest from the terminal with a command : python3 -m pytest "name_of_the_file.py"安装后,我使用命令从终端运行 pytest:python3 -m pytest "name_of_the_file.py"

And that works.这有效。 On Mac I need to prefix all commands with "python3" cause I guess Mac has its own inbuild Python but thats Python 2 so in order to run code on my Pycharm, which was Python 3 , I need that prefix in the command... not sure though I am a newbie but something along those lines I guess在 Mac 上,我需要用“python3”作为所有命令的前缀,因为我猜 Mac 有自己的内置 Python,但那是 Python 2,所以为了在我的 Pycharm(即 Python 3)上运行代码,我需要在命令中使用该前缀...不确定虽然我是新手,但我猜是这样的

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

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