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

Can not import RegionGrowth #1

Open
wangshuxinxinxin opened this issue Jun 29, 2021 · 1 comment
Open

Can not import RegionGrowth #1

wangshuxinxinxin opened this issue Jun 29, 2021 · 1 comment

Comments

@wangshuxinxinxin
Copy link

Hello, I ran the command'python etpy.py build_ext', there seems to be no error, but I still cannot import RegionGrowth. Do you know what could go wrong?

python setpy.py build_ext running build_ext building 'RegionGrowth' extension gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/wangshuxin/anaconda3/envs/torch1.6.0/lib/python3.6/site-packages/numpy/core/include -I/home/wangshuxin/anaconda3/envs/torch1.6.0/include/python3.6m -c RegionGrowth.c -o build/temp.linux-x86_64-3.6/RegionGrowth.o gcc -pthread -shared -L/home/wangshuxin/anaconda3/envs/torch1.6.0/lib -Wl,-rpath=/home/wangshuxin/anaconda3/envs/torch1.6.0/lib,--no-as-needed -L/home/wangshuxin/anaconda3/envs/torch1.6.0/lib -Wl,-rpath=/home/wangshuxin/anaconda3/envs/torch1.6.0/lib,--no-as-needed build/temp.linux-x86_64-3.6/RegionGrowth.o -L/home/wangshuxin/anaconda3/envs/torch1.6.0/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/RegionGrowth.cpython-36m-x86_64-linux-gnu.so

@samchencode
Copy link

samchencode commented Feb 24, 2023

You may have been having trouble with importing the .so file.

I made the package importable by adding an __init__.py file as follows:

import os

def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    import sys, pkg_resources, imp, os

    dll_path = os.path.join('build', 'lib.linux-x86_64-cpython-310', 'RegionGrowth.cpython-310-x86_64-linux-gnu.so') 
    __file__ = pkg_resources.resource_filename(__package__, dll_path)
    __loader__ = None; del __bootstrap__, __loader__
    imp.load_dynamic(__name__, __file__)
__bootstrap__()

With this file in the RegionGrowth directory, a python script right outside this directory should be able to import RegionGrowth

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

2 participants