Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install the python library inside a virtualenv? #3029

Open
munikarmanish opened this issue Jul 23, 2020 · 3 comments
Open

How to install the python library inside a virtualenv? #3029

munikarmanish opened this issue Jul 23, 2020 · 3 comments

Comments

@munikarmanish
Copy link

munikarmanish commented Jul 23, 2020

After following the instructions in the INSTALL.md file, I can successfully import bcc from the system python interpreter (v3.6). But I cannot import bcc from the python within the virtualenv (v3.7). I want to write BPF program with some 3.7 features (time.time_ns) How can I install the python bcc library inside a virtualenv? I'm used to installing per-virtualenv python packages using pip, but this library doesn't seem to have that option. Thanks in advance. :)

@willfindlay
Copy link
Contributor

Are you using pipenv? If so, you can install bcc normally and pass --site-packages as a flag to pipenv as a workaround. As far as I know, there is no good way to get bcc working properly with a virtual environment.

@photoszzt
Copy link

If you already created the virtual env, you can copy the bcc dir to your virtualenv's lib dir. I'm not sure whether symlink would work.

@gukoff
Copy link
Contributor

gukoff commented Jul 12, 2024

You can also workaround this by importing bcc from the global location.
Caveat is that different platforms will have a different "global location", and many platforms try to import from the places like "/usr/lib/python3.10/site-packages/bcc/__init__.py".

Example for Debian:

try:
    import bcc
except ImportError:
    spec = importlib.util.spec_from_file_location("bcc", "/usr/lib/python3/dist-packages/bcc/__init__.py")
    if spec:
        module = importlib.util.module_from_spec(spec)
        sys.modules['bcc'] = module
        spec.loader.exec_module(module)

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

No branches or pull requests

4 participants