擅长:python、mysql、java
<p>我正在使用的是Python.NET我和Python3.6也有类似的问题。我在运行时设置环境变量的运气不太好,但我发现以下方法是有效的。在</p>
<p>我发现了Python.NET正在拾取静态<code>PythonEngine.PythonPath</code>变量中定义的文件夹中的所有包。如果在PYTHONPATH系统变量中设置了其他目录,它也将包括这些目录。在</p>
<p>要在运行时包含模块目录,可以执行以下操作</p>
<pre><code>PythonEngine.PythonPath = PythonEngine.PythonPath + ";" + moduleDirectory;
using (Py.GIL())
{
dynamic module = Py.Import("moduleName");
...etc
}
</code></pre>
<p>确保在调用python引擎之前设置了<code>PythonEngine.PythonPath</code>变量。在</p>
<p>还需要重新启动visualstudio以查看任何系统变量更改在调试时生效。在</p>
<p>另外,我还发现需要将我的\Python36\Lib\site packages文件夹路径添加到PYTHONPATH中,以获取通过pip安装的任何内容。在</p>