pytest system command not found after pip install on ubuntu

Created on 5 May 2019  路  5Comments  路  Source: pytest-dev/pytest

I tried to install pytest on a fresh Ubuntu 18.04 machine,
following the documentation here:
https://docs.pytest.org/en/latest/getting-started.html

I run in the terminal:

pip install -U pytest

the installation was fine, but when running:

pytest --version

I get:

Command 'pytest' not found, but can be installed with:
sudo apt install python-pytest

I also tried to run the same commands inside a virtualenv and it was working properly.

So in the case it is necessary to install pytest inside a virtualenv, this should be clearly specified in the documentation,
otherwise if it is allowed to install pytest directly in the machine without virtualenv, should be fixed the bug.

Thank you a lot

needs information question

All 5 comments

i believe this is a issue with python on ubuntu as well as your path

i suspect that pytest was installed in your user-site, but you don't have that as part of the path

if im right you should be able to run~/.local/bin/pytestand yourPATHneeds the~/.local/bin` entry added

I tried to reboot the ubuntu machine, and after this, pytest works as expected also running it from command line.

OK, thanks for the follow up @fontealpina

1-setup a virtual env to install the package (recommended):

python3 -m venv env
source ./env/bin/activate
python -m pip install pytest

2-Install the package to the user folder:
python -m pip install --user pytest

3-use sudo to install to the system folder (not recommended)
sudo python -m pip install pytest

4- can do
sudo pip install pytest
You might be prompted for your admin password:

@moa210 please do not suggest using sudo pip install, on pretty much most systems its a bad idea

Was this page helpful?
0 / 5 - 0 ratings