【问题标题】:Pytest not working with upgrade to MacOS SierraPytest 无法升级到 MacOS Sierra
【发布时间】:2017-01-17 03:36:25
【问题描述】:

我最近将我的 Mac 从 Mac OSX El Capitan 升级到了 macOS Sierra (10.12.1)。 pytest (link) 在以前版本的 El Capitan 中工作得很好,但现在它通过版本检查抛出以下错误:

$ python3 pytest --version
/Library/Frameworks/Python.framework/Versions/3.5/Resources/Python.app/Contents/MacOS/Python: can't open file 'pytest': [Errno 2] No such file or directory

我认为pytest 可能在升级过程中迷路了。所以,我尝试再次安装它:

$ pip3 install -U pytest     
Requirement already up-to-date: pytest in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages
Requirement already up-to-date: py>=1.4.29 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from pytest)

哎呀,我什至将其删除并重新安装(通过pip3)。不行。

现在,我不必将 python 模块的路径添加到我的.bash_profile(或者在我的情况下,我的.zshrc)。不过需要明确的是,Python 已将我的.zprofile 更新为

# Setting PATH for Python 3.5
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH

为了完整性,

$ which python3
/usr/local/bin/python3

$ echo $SHELL
/bin/zsh

echo $PATH
[...clipped...]:/usr/local/bin:[...clipped...]

我在这里不知所措。如果.zprofile 具有正确的包路径,为什么pytest 不起作用?有谁知道如何让pytest 与 macOS Sierra 一起工作?

注意:我查看了 Google 和 SO,但找不到有用的问题。

编辑:

我忘了在原帖中提到标准不起作用,因为我使用了两个版本的 python

$ pytest --version 
zsh: command not found: pytest

【问题讨论】:

    标签: python-3.x pytest macos-sierra


    【解决方案1】:

    当然。在我发布问题后不久,我记得pytest 需要使用-m 标志(通过python3)来调用模块

    $ python3 -m pytest --version 
    This is pytest version 3.0.5, imported from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pytest.py
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-10
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2018-05-25
      • 2018-02-02
      • 2023-03-20
      相关资源
      最近更新 更多