Search Unity

Question Problem with Python loading Module from script

Discussion in 'Scripting' started by MarcoCarraro1, Mar 23, 2021.

  1. MarcoCarraro1

    MarcoCarraro1

    Joined:
    Mar 15, 2021
    Posts:
    1
    I'm trying to connect a python script ("personal_download.py") inside my Unity app. I call this script with PythonRunner.Runfile(path) method, in this way:

    Code (CSharp):
    1. string scriptPath = "path/of/my/python/script";
    2.             PythonRunner.RunFile(scriptPath);
    Unity is able to read the python script but I have to import a module. In particular, I'm working with the API of freesound.org. So, I have to import the other python file ("freesound.py") in my python scipt, I do it in this way:

    import freesound

    Despite my python script and "freesound.py" being in the same folder, the Unity console keeps on give me this error:

    Code (CSharp):
    1. PythonException: ImportError : No module named freesound
    2. ['  File "<string>", line 1, in <module>/n', '  File "C:/Users/Marco/Documents/Unity/freesound-python-master/personal_download.py", line 3, in <module>/n    import freesound/n']  at Python.Runtime.Runtime.CheckExceptionOccurred () (at <c8fac48adde14fb6a6caf70fb9635324>:0)
    3. Python.Runtime.PythonEngine.RunString (System.String code, System.Nullable`1[T] globals, System.Nullable`1[T] locals, Python.Runtime.RunFlagType flag) (at <c8fac48adde14fb6a6caf70fb9635324>:0)
    4. Python.Runtime.PythonEngine.Exec (System.String code, System.Nullable`1[T] globals, System.Nullable`1[T] locals) (at <c8fac48adde14fb6a6caf70fb9635324>:0)
    5. UnityEditor.Scripting.Python.PythonRunner.RunFile (System.String pythonFileToExecute) (at Library/PackageCache/com.unity.scripting.python@2.1.1-preview.1/Editor/PythonRunner.cs:105)
    (In attachment there's the console error)

    Obv, if I try to run another python script which doesn't need to import freesound module, it runs correctly.
    Hoping someone has an idea about it, thank you very much!
     

    Attached Files:

  2. biyasto

    biyasto

    Joined:
    Dec 9, 2019
    Posts:
    1
    I have the same problem. do you find a solution yet? thank you