在我的C应用程序(x64)中,我使用IronPython(通过nuget安装的v2.7.7)来执行python代码。我手动安装了python 2.7 x64,并在其中安装了spacy包。我可以在C:\Python27x64\Lib\site-packages\spacy找到它。在
当执行C代码时,我从IronPython.Runtime“No module named spacy”得到ImportException。我在网上找到的资源声称应该通过添加正确的路径来解决这个问题,但是在我的例子中这似乎还不够。在
python代码(您可以在下面的C代码中的string变量中看到)是
在import sys
print sys.version
sys.path.append(r'C:\Python27x64\Lib')
import spacy
代码:
^{pr2}$
输出是2.7.7 (IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (64-bit))
后跟IronPython.Runtime.Exceptions.ImportException:没有名为spacy的模块。在
因此,无论是在C中添加路径还是在python代码中添加路径,似乎都没有起到神奇的作用。我还尝试添加路径“C:\Python27x64\Lib\site packages”,但出于某种原因,这是一个非法路径。在
在复制了Lib:\n2c的路径之后,似乎又一次尝试复制了Lib:\n2c的路径,但该路径似乎没有成功。在
堆栈跟踪(我发现在本例中完全没有帮助)是:at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetDirectoryName(String path)
at IronPython.Runtime.Types.DocBuilder.GetXPathDocument(Assembly asm)
at IronPython.Runtime.Types.DocBuilder.GetXmlDoc(Type type, String& summary)
at IronPython.Runtime.Types.DocBuilder.CreateAutoDoc(Type t)
at IronPython.Runtime.Operations.PythonTypeOps.GetDocumentation(Type type)
at IronPython.Runtime.Types.PythonTypeInfo.DocumentationDescriptor.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
at IronPython.Runtime.Binding.MetaPythonType.FastGetBinderHelper.SlotAccessDelegate.Target(CodeContext context, Object self, Object& result)