MusicLang / musiclang_predict

AI Prediction api of the MusicLang package
GNU General Public License v3.0
250 stars 16 forks source link

ctypes.cdll error #25

Open gvossos opened 3 months ago

gvossos commented 3 months ago

Hi, I'm unable to run sample scripts on Windows 11 using Python 3.11.8.

Python throws --> ctypes.CDLL(lib_path) error, --> musiclang\Lib\ctypes__init.py", line 376, in init__ self._handle = _dlopen(self._name, mode), --> FileNotFoundError: Could not find module '....\musiclang\Lib\site-packages\musiclang_predict\c\run.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Any suggestions?

GamingDaveUk commented 3 months ago

Same issue. windows 11. git cloned the repo cd'd into it created a virtual environment: python -m venv venv activated the environment: venv\Scripts\activate created a test.py with the github basic script contents word for word. ran it and after it downloaded the model etc I got:

(venv) D:\AI\musiclang_predict>python test.py
Traceback (most recent call last):
  File "D:\AI\musiclang_predict\test.py", line 9, in <module>
    score = ml.predict(
  File "D:\AI\musiclang_predict\musiclang_predict\predict.py", line 68, in predict
    generated_text = run_transformer_model(
  File "D:\AI\musiclang_predict\musiclang_predict\chelpers.py", line 19, in run_transformer_model
    lib = load_library()
  File "D:\AI\musiclang_predict\musiclang_predict\chelpers.py", line 12, in load_library
    return ctypes.CDLL(lib_path)
  File "C:\Program Files\Python310\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'D:\AI\musiclang_predict\musiclang_predict\c\run.dll' (or one of its dependencies). Try using the full path with constructor syntax.

I noticed in the readme it says to pip install it rather than clone it. so i tried that with a freshfolder, fresh virtual environment and got the following error:

 Running setup.py install for musiclang-predict ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Program Files\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\mrgre\\AppData\\Local\\Temp\\pip-install-wm0d7_rn\\musiclang-predict_24899c5f909b4853b8c3943ef01a8f26\\setup.py'"'"'; __file__='"'"'C:\\Users\\mrgre\\AppData\\Local\\Temp\\pip-install-wm0d7_rn\\musiclang-predict_24899c5f909b4853b8c3943ef01a8f26\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\mrgre\AppData\Local\Temp\pip-record-1b8gsgpe\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\mrgre\AppData\Roaming\Python\Python310\Include\musiclang-predict'
         cwd: C:\Users\mrgre\AppData\Local\Temp\pip-install-wm0d7_rn\musiclang-predict_24899c5f909b4853b8c3943ef01a8f26\
    Complete output (5 lines):
    running install
    running build
    running build_py
    error: [WinError 2] The system cannot find the file specified
    is called install
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Program Files\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\mrgre\\AppData\\Local\\Temp\\pip-install-wm0d7_rn\\musiclang-predict_24899c5f909b4853b8c3943ef01a8f26\\setup.py'"'"'; __file__='"'"'C:\\Users\\mrgre\\AppData\\Local\\Temp\\pip-install-wm0d7_rn\\musiclang-predict_24899c5f909b4853b8c3943ef01a8f26\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\mrgre\AppData\Local\Temp\pip-record-1b8gsgpe\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\mrgre\AppData\Roaming\Python\Python310\Include\musiclang-predict' Check the logs for full command output.

Side note: when going to get the error code again to share here, I forgot to activate my virtual environment.... that may end up being a costly mistake... time will tell but it does show its not the virtual environment effecting it.

floriangardin commented 3 months ago

I don't currently own a windows laptop so it's hard for me to debug that. I don't know if the setup is failing for everyone on this os. If someone managed to get it to work on windows it would be great to let me know. Otherwise I am adding a disclaimer section on the readme.

If you clone it instead of pip install : you need to build the C dependencies (used for faster inference) yourself. You need a C compiler, and there is a makefile in musiclang_predict/c directory, it will build the lib. You can check the setup.py to see what is happening during the setup.

I will work for a more robust setup, but if someone want to give a hand, it would be wonderful !

gvossos commented 3 months ago

Thanks for the note Florian. Yes - hoping someone can help out. For reference, I went down the pip install route.