ionelmc / python-hunter

Hunter is a flexible code tracing toolkit.
https://python-hunter.readthedocs.io/
BSD 2-Clause "Simplified" License
796 stars 46 forks source link

Failed to load hunter from PYTHONHUNTER environ variable ...: ImportError('No module named colorama',) #53

Closed guettli closed 5 years ago

guettli commented 5 years ago

I get this error:

modcron@aptguettler:~$ PYTHONHUNTER="filename_has='check_pro'" tmp/c.py
Failed to load hunter from PYTHONHUNTER environ variable "filename_has='check_pro'": 
    ImportError('No module named colorama',)

I changed lib/python2.7/site-packages/hunter.pth to not catch the exception.

Now I see this:

modcron@aptguettler:~$ PYTHONHUNTER="filename_has='check_pro'" tmp/c.py
Traceback (most recent call last):
  File "/home/modcron/lib/python2.7/site.py", line 703, in <module>
    main()
  File "/home/modcron/lib/python2.7/site.py", line 683, in main
    paths_in_sys = addsitepackages(paths_in_sys)
  File "/home/modcron/lib/python2.7/site.py", line 282, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/home/modcron/lib/python2.7/site.py", line 204, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/home/modcron/lib/python2.7/site.py", line 173, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "<string>", line 4, in <module>
  File "/home/modcron/local/lib/python2.7/site-packages/hunter/__init__.py", line 9, in <module>
    from .actions import Action
  File "/home/modcron/local/lib/python2.7/site-packages/hunter/actions.py", line 11, in <module>
    from colorama import AnsiToWin32
ImportError: No module named colorama

If I try this, importing colorama works:

modcron@aptguettler:~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from colorama import AnsiToWin32

This is very strange: colorama is installed, but hunter can't load it.

Do you have a clue how to debug (and solve) this?

ionelmc commented 5 years ago

I suppose you have 2 python installs? One in /home/modcron and one in /usr? It looks like that, unless you have /home/modcron/bin in your $PATH.

Running /home/modcron/bin/pip instal --ignore-installed hunter. That should install everything even if they appear to be already installed (eg: colorama*.dist-info or colorama*.egg-info present but package actually missing). Running pip uninstall colorama many times can also clean up the orphaned metadata. I suspect it's this, unless you customized your /home/modcron python install with symlinks or patches.

guettli commented 5 years ago

Thank you for your fast reply. I guess I understood it now.

I am running a virtualenv (in $HOME) which was created like this:

virtualenv  --system-site-packages .

Package colorama is from /usr/lib:

pip install colorama
Requirement already satisfied: colorama in /usr/lib/python2.7/dist-packages

And your solution works:

pip install --ignore-installed hunter

Now I see the trace:

PYTHONHUNTER="filename_has='check_pro'" tmp/check_processes

Thank you very much!

ionelmc commented 5 years ago

I guess this can be closed, no clue if I can add anything in the docs about this.

guettli commented 5 years ago

yes, can be closed. thank you