Search code examples
linuxjenkinspathpackagerhel

Packages install but not found


I have packages installed under /usr/local/lib and I added that in my PATH as well, but then I try to import it in any of my python scripts I get an error saying module not found.

-bash-4.2$ pip2 list | grep pytest
pytest-mock                             2.0.0

My PATH:

echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/bin

ERROR:

-bash-4.2$ python2
>>> import pytest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytest

Only if the packages is installed under my /users/user-name/.local/bin folder, it is reflected else it is not.

My usecase is to use this machine as a slave for my Jenkins setup. I tried injecting this PATH directly to the job during build process as well. Didn't work for me.

I have been stuck on this for quite some while, any help on this is greatly appreciated.


Solution

  • First thing, it's generally a good idea to use virtualenv to create Python environments - installing Python packages system-wide is asking for trouble.

    Second, your path may not work because you are setting PATH in the way that Jenkins ignores. The simplest solution is to provide full path to file: /usr/local/bin/pytest.

    The safest way is to combine two above - create virtualenv, install pytest in it and rovide full path when using (note: you don't need to activate virtualenv to use it).