n-y-kim / liblouis-python

how to use liblouis in Python
4 stars 0 forks source link

AttributeError: module 'louis' has no attribute 'translateString' #1

Closed MinHieu2006 closed 1 year ago

MinHieu2006 commented 1 year ago

Hi , nice for your help. I install this project , and extract them. Then i run pip setup.py install. I make new python file. And use this follow code: import louis

print(louis.translateString(["braille-patterns.cti", "en-us-g2.ctb"], "Hello, World!")) and got this error : AttributeError: module 'louis' has no attribute 'translateString' How to fix it? Thanks!

n-y-kim commented 1 year ago

Hi. Can you tell me more specific about your environment & procedure?

And please show me your whole code & error messages

MinHieu2006 commented 1 year ago

Hi , I don't know which steps i am doing wrong. So i push my video when i install this project , and working on it. Sorry for my bad English, and you have a good day! https://drive.google.com/file/d/1MCsyXoAZduP77YMzziR9Dlwyo4c0Niz5/view?usp=share_link

n-y-kim commented 1 year ago

First of all, did you install 'this' project and installed it? I just looked through your video and the contents inside the liblouis python folder made me assume that... You should download the zip file from the original liblouis repo. I will keep this issue opened until you resolve this issue.

(And your English is very fine. No need to worry)

MinHieu2006 commented 1 year ago

I have done it with from original liblouis repo And I do like in my video. Still got this error May be this cause problem? Thank you! image

UPDATE: I read this from original These bindings use ctypes to access the liblouis shared library. The liblouis shared library needs to be located in the library search path. In most cases, if liblouis has been installed in a standard location on your system, this is already the case and the bindings will work without any additional steps.

I think may be I push wrong my liblouis folder. Should I push liblouis in python/Lib or some where?

n-y-kim commented 1 year ago

Please check one more time if you have downloaded the correct file from the liblouis repo. If you downloaded correctly, the folder structure would look like this:

Screenshot 2022-11-26 at 6 37 03 PM

And you should download the whole zip file for the specific release

Screenshot 2022-11-26 at 6 55 28 PM Screenshot 2022-11-26 at 6 55 42 PM

After that, you should do all the steps I have mentioned, such as ./configure, make.. and so on. I could see that you just changed setup.py.in to setup.py. This is not the correct step. If you followed configure, make, install setup.py file would be installed without personal interference.

MinHieu2006 commented 1 year ago

After i check all, You are right! I install wrong repo, and install WSl to run ./configure in win. But I don't understand this

image

I don't know what does "Add function CDLL inside from ctypes import ~" mean. Here my init.py file

image

Is cdll function? And replace code in line 61 with import os path_f = os.path.abspath( os.path.join(os.path.dirname(__file__), "liblouis.so.20")) liblouis = CDLL(path_f)

Finally , I'm glad to have your help!

n-y-kim commented 1 year ago

Hi, glad that you are making progress. First thing first. Before you make changes at init.py, did you have errors(OSError) like I have linked? If you did not have error, you do not have do this step.

If there was an error, it's not cdll. It's CDLL. CDLL is a function imported from package ctype. So it should all be in a capital letter. Hopes this fix every problem you are facing.

I think this would clear up all the errors you are facing.

n-y-kim commented 1 year ago

And you also have to move the liblouis.so.20 file to where I had specified.

MinHieu2006 commented 1 year ago

Hi , i have done your tutorial . In this step , I add CDLL in here (in picture below)

image

And here is my folder image

In python folder image

Finally , I run both in my ubuntu and cmd image

image

I found solution this problem on stackoverflow

May be am wrong in first step? Thank you a lot

n-y-kim commented 1 year ago

The place you are making the test file, a.py is wrong. You should try making them in other folders that do not contain louis folder. Because you are keep doing it in liblouis-3.23.0/python folder, python get confused which louis is it. It should get louis from installed python package library, but it is instead importing from you local liblouis-3.23.0/python folder. This is not about liblouis. It is common knowledge in Python that you should not make a file with the same name of the package you are importing.

What you are doing now which confuses Python:

liblouis-3.23.0/python

louis
Makefile.am
Makefil.in
setup.py
setup.py.in
a.py

Try changing the path you are testing.

For windows environment, the last OSError message seems disturbing. Maybe it's because of the permission error? I cannot give a solution for this error... maybe try looking up at the original liblouis repo or google. I'm closing this issue as I think you can resolve the issue by yourself now 😉