我正在尝试开发一个在 .net 中嵌入 python 的简单计算器程序,我想引用 NuGet 中的 pythonnet 将其包含在我的项目中
我使用 NuGet 安装了 pythonnet v2.3.0,我的系统中还安装了 python 3
如果有人给我嵌入 python net 的分步说明,那就太好了
form1.cs代码:
using System;
...
using Python.Runtime;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
PythonEngine.Initialize();
}
private void button1_Click(object sender, EventArgs e)
{
int num1 = int.Parse(a.Text);
int num2 = int.Parse(b.Text);
result.Text = (num1 + num2).ToString();
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
using(Py.GIL())当我在代码中使用line 时,编译器会显示
System.BadImageFormatException:“无法加载文件或程序集“Python.Runtime,Version=2.3.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。尝试加载格式不正确的程序。”
我正在尝试动态设置相机在场景中的位置和大小,如果我执行以下代码,则会发生错误。如果我在场景中设置属性,它会正常工作,因此错误在我的代码中
错误:屏幕位置超出视锥体(屏幕位置 959.000000、454.000000)(相机矩形 0 0 960 907)UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
using UnityEngine;
public class CameraInt : MonoBehaviour
{
public Camera cam1;
private int row, col;
private float size;
void Start()
{
MazeLoader ml = gameObject.AddComponent<MazeLoader>();
row = ml.mazeRows;
col = ml.mazeColumns;
size = ml.size;
float r = row * size / 2;
cam1.transform.Translate(new Vector3(r, 0,col*size/2),Space.World);
cam1.orthographicSize = r;
}
}
Run Code Online (Sandbox Code Playgroud)