Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

ModuleNotFound within virtualenv/ virtual environment #164

Open
arthur-e opened this issue Aug 12, 2019 · 1 comment
Open

ModuleNotFound within virtualenv/ virtual environment #164

arthur-e opened this issue Aug 12, 2019 · 1 comment

Comments

@arthur-e
Copy link

I'm trying to use kernprof with a script that is used in a virtual environment (created with virtualenv). This virtual environment uses some system-wide packages (i.e., with --system-site-packages) but some are also local to the virtual environment. It seems that kernprof can't locate these modules? In the example below, it can't find the cached_property module, but a quick pip freeze confirms that, indeed, this module is available.

$ kernprof -l myscript.py 
Wrote profile results to myscript.lprof
Traceback (most recent call last):
  File "/usr/local/bin/kernprof", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/kernprof.py", line 222, in main
    execfile(script_file, ns, ns)
  File "/usr/local/lib/python3.6/dist-packages/kernprof.py", line 35, in execfile
    exec_(compile(f.read(), filename, 'exec'), globals, locals)
  File "pyl4c/apps/soc.py", line 26, in <module>
    from cached_property import cached_property
ModuleNotFoundError: No module named 'cached_property'
$ pip freeze | grep cached
cached-property==1.5.1

I confirmed that switching a module from a local to a system-wide install fixed this issue; i.e., after removing cached_property from the virtual environment and installing system-wide with sudo -H pip install cached_property, kernprof moved on to complain about a different module.

Here are my stats:

  • Python 3.6.8
  • pip version 19.2.1
  • virtualenv version 15.1.0
  • kernprof version 1.0b2

Thanks!

@xuezes
Copy link

xuezes commented Sep 17, 2019

ran into the same problem today. For my case is that I can find two

kernprof: /home/user_name/.local/bin/kernprof /home/user_name/some/env/dirs/bin/kernprof

by running whereis kernprof. I suspect when one call kernprof the system prioritizes to call the first one, which is not the one in the virtual environment.

calling

/home/user_name/some/env/dirs/bin/kernprof some_code.py plus_args

(Or just simply delete the first one :-/) will resolve the problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants