I'm making a .net core app for Linux. The app make use of the pythonnet library to interact with python modules on the Linux box.
I'm trying to do some Debian package management using the python-apt module e.g. the apt.cache
class.
This native python script works fine running directly on Linux printing all packages:
import apt
cache = apt.Cache()
for pkg_name in cache.keys():
print(pkg_name)
My VB.net core code where I have a problem to declaring the apt.Cache()
object correctly:
Runtime.PythonDLL = "/usr/lib/python3.9/config-3.9-x86_64-linux-gnu/libpython3.9.so"
Python.Runtime.PythonEngine.PythonHome = "/usr/lib/python3.9"
PythonEngine.Initialize()
Using Py.GIL
Dim apt As PyObject = Py.Import("apt_pkg")
Dim cache As PyDict = apt.Cache()
...
End Using
I get the exception:
_system not initialized at Python.Runtime.PythonException.ThrowLastAsClrException() at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw) at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw) at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at CallSite.Target(Closure , CallSite , Object ) at CallSite.Target(Closure , CallSite , Object ) at Microsoft.VisualBasic.CompilerServices.IDOUtils.CreateRefCallSiteAndInvoke(CallSiteBinder action, Object instance, Object[] arguments) at Microsoft.VisualBasic.CompilerServices.IDOBinder.IDOGet(IDynamicMetaObjectProvider instance, String memberName, Object[] arguments, String[] argumentNames, Boolean[] copyBack) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object instance, Type type, String memberName, Object[] arguments, String[] argumentNames, Type[] typeArguments, Boolean[] copyBack) at py_test_vb_core.Program.Main(String[] args) in Y:\Development projects~3rd part libraries\pythonnet\py_test_vb_core\py_test_vb_core\Program.vb:line 17
The documentation says apt.Cache()
is a "dictionary-like object"
I use Visual Studio on Windows and I can connect to Linux box with SSH and can debug the .net core application just fine.
An additional questions: Is it possible to expose all class members etc. of the native python python-apt module in Visual Studio debugger? I don't dare to hope for IntelliSense support, but it would be a big help if I could see class members etc. of the python-apt
module in the debug? It would also have helped me in declare the above object correctly.
(help in c# is also fine)