Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Py.test command not found, but library is installed

There are already two posts on stack overflow on this topic; however, none of them have resolved or addressed my specific situation.

I have installed pytest via pip install pytest. I am able to import the library in Python as well.

The problem is that when I try to use the py.test command in Terminal, I get py.test: command not found.

Does anyone have any insight as to why I am not able to use the command in the terminal?

EDIT: It even shows up as an installed package:

$ 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)
like image 828
E. Otero Avatar asked Mar 14 '16 22:03

E. Otero


3 Answers

using python -m pytest will work for you.

Or if you using virtual environment and installed pytest on virtualenv you should then run py.test alongside your virtual environment.

Check this website can be useful:http://pythontesting.net/framework/pytest/pytest-introduction/

like image 171
Ehsan Maiqani Avatar answered Oct 14 '22 00:10

Ehsan Maiqani


Are you on a mac with homebrew by any chance?

I had the same issue and it basically came down to permissions/conflict with the mac os base installed python. pip install would not install or link stuff into /usr/local/bin (it happened with both virtualenv and pytest).

  1. I uninstalled python 2.7 completely with homebrew (brew uninstall python).
  2. Next, I reinstalled python with homebrew to fix pip (it was not a symlink in /usr/local/bin/pip where it should have been linked to Cellar) -- brew install python
  3. Then I uninstalled pip with sudo -- sudo python -m pip uninstall pip to remove the pip owned by root
  4. Now I uninstalled and reinstalled python with homebrew again to reinstall pip with the correct permissions brew uninstall python && brew install python
  5. Next I fixed the python symlinks brew link python
  6. Finally, pip install pytest worked! (and so did pip install virtualenv)

I found the information in the chosen answer from this post very helpful: https://superuser.com/questions/915810/pip-not-working-on-hombrew-python-2-7-install.

If you're not on a mac, sorry for the noise...

like image 38
Ugtar Avatar answered Oct 13 '22 22:10

Ugtar


I already had the latest version of pytest on macOS with Homebrew-installed Python 2.7 and this fixed it:

pip uninstall pytest
pip install pytest
like image 12
Hugo Avatar answered Oct 13 '22 23:10

Hugo