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't move the build/Release/bin folder into a new location #29

Open
mborus opened this issue Jan 7, 2025 · 2 comments
Open

Can't move the build/Release/bin folder into a new location #29

mborus opened this issue Jan 7, 2025 · 2 comments

Comments

@mborus
Copy link

mborus commented Jan 7, 2025

Hi - thanks for writing this library.

I'm trying to use the Python connection to just decode the binary content on of the bar code on a Debian system and it works decoding the bar codes.

These are the steps taken

cd ~
git clone https://github.com/user4223/ticket-decoder.git
sudo apt-get install --no-install-recommends -y build-essential cmake python3-pip python3-dev python-is-python3
python3.12 -m venv venv_bahn
source venv_bahn/bin/activate
pip3 install "conan<2.0" "numpy<2.0"
# scary red warning "WARNING: GCC OLD ABI COMPATIBILITY *" appears after the next step!!!
conan profile new ticket-decoder --force --detect
conan profile update settings.compiler.libcxx=libstdc++11 ticket-decoder
cd ticket-decoder
sh setup.Python.sh

I then copied the "bin" folder into the current virtual environment "/venv_bahn/bin" - which let me import
from ticket_decoder import DecoderFacade as long as I manually put this folder on the path. I used sys.path.append("/home/<removed>/venv_bahn/bin") to do this.

However, as soon as I remove/rename the created "build/Release/bin" folder from my home directory, the import no longer works. This is the error.

ImportError: libticket-decoder-uic918-u_flex13.so: cannot open shared object file: No such file or directory

Changing the name back fixes the problem. So I need to keep the build files in my home directory permanently.

Is there a way to move the ticket-decoder inside a virtual environment so that I can delete the files used to build it?

@mborus mborus changed the title Can't move the build/Release/bin folder into a ew location Can't move the build/Release/bin folder into a new location Jan 7, 2025
@user4223
Copy link
Owner

user4223 commented Jan 7, 2025

hi mborus, i never tried this. but i will try to reproduce...

as a first guess: i tried to link almost all statically to avoid such problems, but the modules containing the generated u_flex stuff are shared libs, because they would get duplicated symbols otherwise for different versions.
i think those two libs (libticket-decoder-uic918-u_flex13.so and ....30.so as well) have to be located in one of the paths in LD_LIBRARY_PATH to be detected properly by the python module.

i think you could try to move the ticket_detector folder to your target location and then you could try to append LD_LIBRARY_PATH to point to the folder containing the libs. i guess python has some mechanism for this, because i think other python modules might have shared lib dependencies as well. but i don't know exactly right now.

@user4223
Copy link
Owner

user4223 commented Jan 11, 2025

i think i know whats going on and why you are facing this behavior now. the setup.Python.sh script exports the PYTHONPATH env var after build

export PYTHONPATH=${WORKSPACE_ROOT}/build/Release/bin

or the PYTHONPATH is specified manually somehow to point to this location. so even when you copy the directory of the package to your separated venv, the PYTHONPATH still points to /build/Release/bin and uses the ticket_decoder module and/or the shared libs from this path. when you change the structure, it's unable to discover the shared libs on load.

for temporary use, you can re-define the PYTHONPATH env var to point to another location, but this location should be structured like this:

your_new_location
| - libticket-decoder-uic918-u_flex13.so
| - libticket-decoder-uic918-u_flex30.so
| - ticket_decoder
    | -  __init__.py
    | - ticket_decoder.so

this should at least work to get it running with export PYTHONPATH=.../what/ever/your_new_location.

but honestly, this is error prone and - for sure - not the normal way to install python modules. so when i have some time for this, i will try to provide the requirements get it installed via setuptools and stuff like this.

contributions welcome

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