相关疑难解决方法(0)

使用 IronPython 时如何设置 Anaconda 虚拟环境?

我想使用 IronPython 在 C# 中运行 python 脚本。除了 IronPython 使用我的基础 Python 安装而不是 Anaconda 环境之外,它运行良好。

我尝试将脚本作为普通进程(即没有 IronPython)运行并将脚本作为参数传递。这有效,但我失去了 IronPython 的功能。例如,查询 Python 变量的能力。

我还尝试将“Python”字符串替换为 anaconda 环境中 Python.exe 的位置以及 Anaconda 环境的名称,但会导致“未知语言”错误。

var runtime = Python.CreateRuntime();
var engine = runtime.GetEngine("Python");   //I've tried replacing this with location of python.exe in the Ananconda environment but it fails

var script = "C:\\Documents\\my_pythonScript.py";
var source = engine.CreateScriptSourceFromFile(script);
var eIO = engine.Runtime.IO;

var results = new MemoryStream();
eIO.SetOutput(results, Encoding.Default);

var scope = engine.CreateScope();
source.Execute(scope);   

string str(byte[] x) => Encoding.Default.GetString(x);
string Results …
Run Code Online (Sandbox Code Playgroud)

c# python environment ironpython anaconda

9
推荐指数
1
解决办法
962
查看次数

安装Python包 - IronPython

我想将PRAW包添加到VS中的IronPython解决方案中,但它确实是一个痛苦的屁股.这是我正在采取的步骤

  • 右键单击IronPython Environment,选择install python package.
  • 使用pip键入"Praw"
  • 我得到一个提示,告诉我pip需要安装.

然后我看到以下内容:

Installing 'pip' package manager.
Downloading distribute from https://go.microsoft.com/fwlink/?LinkID=306663
Installing from distribute-0.6.45
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at c:\program files (x86)\ironpython 2.7\lib\site-packages\setuptools-0.6c11-py2.7.egg
Egg installation
Already patched.
running install
Traceback (most recent call last):
  File "setup.py", line 147, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\Lib\distutils\core.py", line 151, in setup
  File "C:\Program Files (x86)\IronPython 2.7\Lib\distutils\dist.py", line 952, in run_commands
  File "C:\Program Files (x86)\IronPython 2.7\Lib\distutils\dist.py", line 971, in run_command
  File "c:\users\mj\appdata\local\temp\ptvs-9jvsvw-pip_downloader\distribute-0.6.45\setuptools\command\install.py", line …
Run Code Online (Sandbox Code Playgroud)

python ironpython ptvs

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

ironpython ×2

python ×2

anaconda ×1

c# ×1

environment ×1

ptvs ×1