2

I am trying to run Python code which uses Scapy functionality from C# using IronPython.

I get the following exception:

IronPython.Runtime.Exceptions.ImportException: 'No module named scapy'

I've already added everything I could to engine search paths:

paths.Add(@"C:\Program Files (x86)\IronPython 2.7\Lib");
            paths.Add(@"C:\Python27\Lib"); // or you can add the CPython libs instead
            paths.Add(@"C:\Python27\Scripts");
            paths.Add(@"C:\\Python27\\lib\\site - packages\\scapy - git_archive.dev2ef25578b - py2.7.egg");
            paths.Add(@"C:\\windows\\SYSTEM32\\python27.zip");
            paths.Add(@"C:\\Python27\\DLLs");
            paths.Add(@"C:\\Python27\\lib\\plat-win");
            paths.Add(@"C:\\Python27\\Lib\\site-packages\\scapy-git_archive.dev2ef25578b-py2.7.egg\\scapy");
            paths.Add(@"C:\\Python27");
            paths.Add(@"C:\\Python27\\lib\\site-packages");

If I try to use other Python module functionality, like for example, math, the script runs.

While searching for the solution I've stumbled across this information:

https://grokbase.com/t/python/ironpython-users/1546gp6gt1/import-error-scapy-on-ironpython-windows

Where the bottomline is:

"You're right that IronPython does not support pywin32, because IronPython doesn't support C extensions in general. In this specific case it's probably because scapy checks for Windows using sys.platform == 'win32' instead of os.name == 'nt' and it's trying to run a Unix codepath (uname is the giveaway, it's part of os on Unix but not Windows)."

But that post is from 2015, is it still relevant? I know that Scapy improved a lot since then regarding compatibility and ease of use from Windows.

Alx Mx
  • 177
  • 9
  • Maybe related: https://stackoverflow.com/questions/23511569/net-framework-with-scrapy-python – doctorlove May 30 '19 at 09:53
  • I've read it. Some issues described are from 10 years ago. Plans are mentioned to adapt twisted engine for IronPython, but not sure any progress was made. – Alx Mx May 30 '19 at 09:59
  • That other post has nothing to do with your immediate problem. In your case, IronPython simply isn't able to find the scapy module directory at all. I don't know much about either IronPython or C#, but normally one adds to `PYTHONPATH` as needed to add modules unless they are in the built-in python paths (it isn't clear to me if that's what your `paths.Add` above is doing). Although from documentation I see in web search, that should actually be `IRONPYTHONPATH` for IronPython. – Gil Hamilton May 30 '19 at 16:32
  • Yes. I've noticed that it is talking about scrapy, not scapy. – Alx Mx Jun 03 '19 at 11:28

0 Answers0