GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing mail.python.org — Mailman 3 - Python.NET - python.org Python.NET
Threads by month
Hi, I am using Python.Runtime in C#,
I would like to call 1 function from my script, this function must work in multip process.
when I call it, it looks like that the sw keep opening new processes forever till my computer has to be restarted it is like a virus,
my python code:
import math
import multiprocessing
import time
from multiprocessing import pool
import cv2
import numpy as np
import os
from PIL import Image
from GraininessFunction import GraininessFunction
#multiprocessing.set_start_method('spawn', force=True) # or 'fork' on Unix
def getString():
return "Hello from Python!"
def worker(x):
print(f"Processing {x} in PID {os.getpid()}")
return x * x
def multiProcessTest():
multiprocessing.freeze_support()
#multiprocessing.freeze_support()
args = [1,2,3,4]
processes = []
print(f"multiProcessTest in PID {os.getpid()}")
for item in args:
print("creating process for:"+str(item))
p = multiprocessing.Process(target=worker, args=(item,))
p.start()
processes.append(p)
for p in processes:
p.join()
#with multiprocessing.Pool(processes=2) as pool:
# pool.map(worker, args)
#multiprocessing.freeze_support()
#if multiprocessing.get_start_method(allow_none=True) != 'spawn':
# multiprocessing.set_start_method('spawn', force=True)
my C# code:
var ret = module.getString();
Console.WriteLine($"Result from Python: {ret}");
module.multiProcessTest();
Console.WriteLine($"end multiProcessTest");
Hello,
has anyone successfully used multithreading or multiprocessing with Python.Net?
I tried to multi-thread from the .Net side and the Python.Net libraries seem to have issues in the RunScript method. I had to take an implementation off the web of that method because the shipped method doesn’t seem to work.
I then had a working multi-processing example from CPython that I tried from Python.Net but it gives an error
'module' object has no attribute 'argv'
When trying to create a process pool by executing the line
pool = Pool(processes=4)
Is it possible to do multithreading or multiprocessing with Python.Net?
Thanks,
Alan
My goal is to write a python script for analyzing C# code by way of the Roslyn API. I'm running into a lot of issues with imports. I'm installing nuget packages then using python code to find the path to the relevant DLL using AddRef but subsequent imports throw. Does anyone have any examples of using Roslyn?
Aug. 18, 2024
Dear Pythonnet Support Team,
I am currently working on a Unity project where I am using the Pythonnet
library to integrate Python scripts with C# code. Specifically, I am
attempting to utilize the HugChat library from within my Unity project.
However, I have encountered the following error:
PythonException: SystemError : initialization of md__mypyc did not return
an extension module
[' File
"C://Users//HOME/u3000anyone//AppData//Local//Programs//Python//Python38//lib//site-packages//hugchat//hugchat.py",
line 1, in <module>/n import requests/n', ' File
"C://Users//HOME/u3000anyone//AppData//Local//Programs//Python//Python38//lib//site-packages//requests//__init__.py",
line 48, in <module>/n from charset_normalizer import __version__ as
charset_normalizer_version/n', ' File
"C://Users//HOME/u3000anyone//AppData//Local//Programs//Python//Python38//lib//site-packages//charset_normalizer//__init__.py",
line 24, in <module>/n from .api import from_bytes, from_fp, from_path,
is_binary/n', ' File
"C://Users//HOME/u3000anyone//AppData//Local//Programs//Python//Python38//lib//site-packages//charset_normalizer//api.py",
line 5, in <module>/n from .cd import (/n', ' File
"C://Users//HOME/u3000anyone//AppData//Local//Programs//Python//Python38//lib//site-packages//charset_normalizer//cd.py",
line 14, in <module>/n from .md import
is_suspiciously_successive_range/n'] at
Python.Runtime.Runtime.CheckExceptionOccurred () (at
<7702cb0f55bd42e3a72a1a6382f5edbc>:0)
Python.Runtime.PythonEngine.ImportModule (System.String name) (at
<7702cb0f55bd42e3a72a1a6382f5edbc>:0)
Python.Runtime.Py.Import (System.String name) (at
<7702cb0f55bd42e3a72a1a6382f5edbc>:0)
AIVtuberProject.get_response () (at Assets/Scripts/AIVtuberProject.cs:31)
AIVtuberProject.main_func () (at Assets/Scripts/AIVtuberProject.cs:75)
AIVtuberProject.OnSendButtonClicked () (at
Assets/Scripts/AIVtuberProject.cs:82)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0
(System.Object state) (at <b89873cb176e44a995a4781c7487d410>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at
<10871f9e312b442cb78b9b97db88fdcb>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at
<10871f9e312b442cb78b9b97db88fdcb>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at
<10871f9e312b442cb78b9b97db88fdcb>:0)
This error occurs when trying to import the requests module within HugChat.
I have confirmed that all necessary Python packages are installed and
accessible. I am using Python 3.8 with Pythonnet version 2.5.2.
I would greatly appreciate your assistance in resolving this issue. If you
need any additional information, please let me know.
Thank you in advance for your help.
Best regards,
Kouno Teruki
Nov. 22, 2023
Hi,
I have a project in C# and visual studio 2022. The project uses a few scripts in python that are embedded in C# code using the Python.Net interface. I have used the application with several several different versions of python and wotkd perfectly.
I am looking a descrptive and usable way to be able to debug my python code while I am in C# code and debugging it. In other words to be able to break in python code from C# code.
With IronPython this was doable in Visual studio but I am not using IronPython anymore.
Thanks in advance.
IK
Hi,
I'm newly trying to use python .NET to embed some C# dlls into my python program. I'm very new to anything .NET, so I apologize if this is a simple question. In order to execute part of the program I need to submit some information back to an object in one of the dlls. This class is expecting an ObservableCollection of objects. I tried submitting a python list, but got an error that it couldn't be converted to the correct type. Unfortunately I can't share the API I'm using for licensing reasons, but here's a short pseudo code of the C# (using 'vegetable' to stand in for some proprietary object types):
private ObservableCollection<VegetableRecord> vegetableRecords
private VegetableSequence VegetableSequence
....
newVegetableRecord1 = new VegetableRecord('Potato')
newVegetableRecord2 = new VegetableRecord('Carrot')
vegetableRecords.Add(newVegetableRecord1)
vegetableRecords.Add(newVegetableRecord2)
...
VegetableSequence.SequenceRecordSet = vegetableRecords
I'm trying to recreate this in python, essentially, using the VegetableRecord and VegetableSequence imported from the dll :
vegetableRecords = []
VegetableSequence = VegetableSequence()
....
newVegetableRecord1 = VegetableRecord('Potato')
newVegetableRecord2 = VegetableRecord('Carrot')
vegetableRecords.append(newVegetableRecord1)
vegetableRecords.append(newVegetableRecord2)
...
VegetableSequence.SequenceRecordSet = vegetableRecords
That fails with an error that is essentially:
TypeError: 'list' value cannot be converted to System.Collections.Generic.ICollection`1[VegetableRecord]
Any advice?
Thanks!
- Jesse
Doubt about compatibility between Python version and Pythonnet
by Alvaro Castro, Fernando April 26, 2023 April 26, 2023
Hello,
I contact you because we are doing some tests using Python 3.10 and Python 3.8. We have seen that using Python 3.8 we can install pythonnet 2.5.2, but using Python 3.10 pythonnet 2.5.2 installation failed. In the information of Pythonnet it seems that 2.5.2 can be installed with Python versions between 3.7 and 3.11.
Can you help me with this please? Is there any manner or procedure to install this specific pythonnet version with Python 3.10?
Thank you in advance.
Fernando.
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Windows 11. Visual Studio 2022. Python311 install and working using VSCode. Pythonnet installed using VS 2022 nuget and pip3 in command prompt
I have this code and it is failing at import pyproj - error is no _socket
Help appreciated
public AzimuthBoundingBoxCalculator()
{
string? GetPythonLib()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return "/Library/Frameworks/Python.framework/Versions/3.11/lib/libpython3.11.dylib";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return @"C:\Users\basic\AppData\Local\Programs\Python\Python311\python311.dll";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|| RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
{
return "libpython3.11.so";
}
return null;
}
string pythonDll = GetPythonLib();
Runtime.PythonDLL = pythonDll;
Environment.SetEnvironmentVariable("PYTHONNET_PYDLL", pythonDll);
PythonEngine.Initialize();
_gilState = Py.GIL();
using (Py.GIL())
{
dynamic pyproj = Py.Import("pyproj");
_geod = pyproj.Geod(ellps: "WGS84");
}
}
Regards
Mark Gregory
In Yocto project python3-pythonnet module is available from now, feel free to use for any embedded Linux image build.
https://layers.openembedded.org/layerindex/recipe/327446/
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |