模块“随机”从 IronPython 2.6 脚本构建 .exe 时未找到
我正在使用 SharpDevelop 从 IronPython 脚本构建可执行文件。唯一的问题是我的脚本有一行 随机导入 当我通过 ipy.exe 运行脚本时,它工作得很好,但是当我尝试从 SharpDevelop 中的脚本构建并运行 exe 时,我总是收到消息:
IronPython.Runtime.Exceptions.ImportException: No module named random
为什么 SharpDevelop “看到”随机的?我怎样才能让它看到呢?
I am using SharpDevelop to build an executable from my IronPython script. The only hitch is that my script has the line
import random
which works fine when I run the script through ipy.exe, but when I attempt to build and run an exe from the script in SharpDevelop, I always get the message:
IronPython.Runtime.Exceptions.ImportException: No module named random
Why isn't SharpDevelop 'seeing' random? How can I make it see it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 ipy.exe 运行 IronPython 脚本时,Python 标准库的路径通常由以下之一确定:
SharpDevelop 生成的 IronPython 可执行文件不会执行这些初始设置任务。因此,在导入随机库之前,您需要添加一些额外的启动代码。您可以通过以下几种方法来执行此操作:
将 Python 标准库的位置直接添加到 sys.path。
从 IRONPYTHONPATH 环境变量获取 Python 标准库的位置。
从注册表中读取 Python 标准库的位置 (HKLM\Software\Python\PythonCore\2.6\PythonPath)。
从应用程序附带的单独配置文件中读取 Python 标准库的位置。
另一种选择是 将应用程序所需的 Python 标准库部分编译为一个或多个 .NET 程序集。这样,您将不需要应用程序的最终用户安装 Python 标准库。
When you run an IronPython script with ipy.exe the path to the Python Standard Library is typically determined from one of the following:
An IronPython executable produced by SharpDevelop will not do these initial setup tasks. So you will need to add some extra startup code before you import the random library. Here are a few ways you can do this:
Add the location of the Python Standard Library to sys.path directly.
Get the location of the Python Standard Library from the IRONPYTHONPATH environment variable.
Read the location of the Python Standard Library from the registry (HKLM\Software\Python\PythonCore\2.6\PythonPath).
Read the location of the Python Standard Library from a separate config file that you ship with your application.
Another alternative is to compile the parts of the Python Standard Library your application needs into one or more .NET assemblies. That way you will not need the end user of your application to have the Python Standard Library installed.