gtalarico / ironpython-stubs

Autocomplete stubs for common IronPython/.NET libraries
Other
248 stars 80 forks source link

Module cannot run #28

Closed johnnyontheweb closed 2 years ago

johnnyontheweb commented 2 years ago

Hello all, I'm trying use ironstubs module to create auto-completion for my .NET library. I'm using IronPython 3.4 and I placed the "ironstubs" folder in Lib directory (but the same behaviour happens if I use the code from outside that folder). I added the path of my DLL in default_settings.py and launched ipy -m ironstubs myDLLname. I get ImportError or ModuleNotFoundError exceptions on every import - the first I get is: ModuleNotFoundError: No module named 'utils'

or

ImportError: No module named 'ConfigParser'

For utils error, I noticed that the error is gone when I correct the import statement in ironstubs.utils, and so on for all the import in the code. I started editing the code, but errors continues to appear, e.g.: Unhandled exception: Traceback (most recent call last): File ".\runpy.py", line 182, in run_module File ".\ironstubs\generator3\pycharm_generator_utils\module_redeclarator.py", line 3, in <module> File ".\runpy.py", line 95, in _run_module_code File ".\runpy.py", line 85, in _run_code File ".\ironstubs\__main__.py", line 34, in <module> File "<string>", line 539, in _check_name_wrapper File "<string>", line 1614, in load_module File "<string>", line 596, in _load_module_shim File "<string>", line 1220, in load File "<string>", line 1200, in _load_unlocked File "<string>", line 1129, in _exec File "<string>", line 1471, in exec_module File "<string>", line 321, in _call_with_frames_removed File ".\ironstubs\make_stubs.py", line 40, in <module> File "<string>", line 539, in _check_name_wrapper File "<string>", line 1614, in load_module File "<string>", line 596, in _load_module_shim File "<string>", line 1220, in load File "<string>", line 1200, in _load_unlocked File "<string>", line 1129, in _exec File "<string>", line 1471, in exec_module File "<string>", line 321, in _call_with_frames_removed File ".\ironstubs\generator3\generator3.py", line 8, in <module> File "<string>", line 539, in _check_name_wrapper File "<string>", line 1614, in load_module File "<string>", line 596, in _load_module_shim File "<string>", line 1220, in load File "<string>", line 1200, in _load_unlocked File "<string>", line 1129, in _exec File "<string>", line 1471, in exec_module File "<string>", line 321, in _call_with_frames_removed ImportError: No module named 'util_methods'

What am I missing? Why do I have to fully qualify the path for every module imported? Running with -X:FullFrames does not help.

thnks in advance

johnnyontheweb commented 2 years ago

The same without placing the ironstubs folder in Lib, on another Windows 10 pc. I unpacked the repo in a folder on my desktop, and run a shell from inside it.

ipy -m ironstubs make HTL --path=r"C:\Users\User\Desktop\myDLLname.dll" --output stubs.min
Unhandled exception:
Traceback (most recent call last):
  File "C:\Program Files\IronPython 3.4\Lib\runpy.py", line 182, in run_module
  File ".\ironstubs\__main__.py", line 30, in <module>
  File "C:\Program Files\IronPython 3.4\Lib\runpy.py", line 95, in _run_module_code
  File "C:\Program Files\IronPython 3.4\Lib\runpy.py", line 85, in _run_code
ImportError: No module named 'utils.docopt'

I feel this is not the normal behaviour, maybe I'm missing a trivial setting. Anyone?

johnnyontheweb commented 2 years ago

Well, the trivial thing was to use ipy 2.7, error changed but still not working:

ipy -m ironstubs make --path=r"C:\Users\User\Desktop\myDLLname.dll" --output stubs.min
Unhandled exception:
Traceback (most recent call last):
  File "C:\Program Files\IronPython 2.7\Lib\runpy.py", line 187, in run_module
  File "C:\Users\Giovanni\Downloads\ironpython-stubs-master\ironstubs\utils\docopt.py", line 579, in docopt
  File "C:\Program Files\IronPython 2.7\Lib\runpy.py", line 81, in _run_module_code
  File "C:\Program Files\IronPython 2.7\Lib\runpy.py", line 72, in _run_code
  File "C:\Users\Giovanni\Downloads\ironpython-stubs-master\ironstubs\__main__.py", line 63, in <module>
ironstubs.utils.docopt.DocoptExit: Usage:
      ironstubs --help
      ironstubs make (<assembly-name>|--all) [options]
      ironstubs minify <folder> [options]
galaplexus commented 2 years ago

Just had the same issue. Solved it fully by using IronPython 2.7 rather than the alpha 3.4 I'm not sure this program supports python 3. Otherwise, you should add the %repo/iron_stubs directory in your IRONPYTHONPATH variable.

johnnyontheweb commented 2 years ago

Hello, thanks for replying. I added IRONPYTHONPATH = C:\Users\Giovanni\Downloads\ironpython-stubs-master\ironstubs as env. variable, but still getting:

================================================================================
[INFO] Making [myDLLname] [2022:01:31 - 10:40:56]
Unhandled exception:
Traceback (most recent call last):
  File "C:\Program Files\IronPython 2.7\Lib\runpy.py", line 187, in run_module
  File "C:\Program Files\IronPython 2.7\Lib\runpy.py", line 81, in _run_module_code
  File "C:\Users\Giovanni\Downloads\ironpython-stubs-master\ironstubs\make_stubs.py", line 140, in make
  File "C:\Program Files\IronPython 2.7\Lib\importlib\__init__.py", line 37, in import_module
  File "C:\Program Files\IronPython 2.7\Lib\runpy.py", line 72, in _run_code
  File "C:\Users\Giovanni\Downloads\ironpython-stubs-master\ironstubs\__main__.py", line 100, in <module>
ImportError: No module named myDLLname
galaplexus commented 2 years ago

I solved it by adding 'C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib' on the Path in the ironstucs\default_settings.py file. You can debug by trying to import the dll from the ipy interactive console.

galaplexus commented 2 years ago

Sorry, I wanted to update the doc but I don't see to have permissions.

johnnyontheweb commented 2 years ago

I tried to import the assembly via clr, it does not work. Do you mean including the path resolve this?

  File "<stdin>", line 1, in <module>
IOError: System.IO.FileLoadException: Il nome o la codebase dell'assembly specificato non è valido. (Eccezione da HRESULT: 0x80131047)
   in System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
   in System.Reflection.AssemblyName..ctor(String assemblyName)
   in System.Reflection.Assembly.LoadWithPartialName(String partialName)
   in IronPython.Runtime.ClrModule.LoadAssemblyByPartialName(String name)
   in IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
   in IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
   in Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   in Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   in Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   in IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   in Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   in Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   in IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   in IronPython.Hosting.PythonCommandLine.<>c__DisplayClass27_0.<RunOneInteraction>b__0()
galaplexus commented 2 years ago

Well I've never had this error. It seems that the name you've added is incorrect. Can you share more? Note that you are supposed to the path uses \\

johnnyontheweb commented 2 years ago

Not if you use the "r" to denote un-escaped string, like r"C:\Users\User\Desktop\myDLLname.dll"

galaplexus commented 2 years ago

Right, so in the path, you are supposed to put the directory name like r"C:\Users\User\Desktop"

johnnyontheweb commented 2 years ago

You were right, it finally worked with ipy -m ironstubs make myDLLname --path=r"C:\\Users\\User\\Desktop\\" It didn't needed to add any Path in the ironstubs\default_settings.py file. Output will be in \release\stubs folder. Thanks for your help