我的 SDK 有自己的 python 解释器。如何为其安装模块?
我最近下载了 python-ogre SDK,它似乎包含它自己的 python 解释器。
我说“出现”是因为这个解释器似乎也依赖于标准 python 2.7.2 安装。我尝试卸载后者,但 python-ogre SDK 解释器抱怨我的计算机中缺少 python27.dll。
我真的不明白这两个解释器是如何相关的,以及 python-ogre SDK 论坛主题 没什么帮助。
我真的需要安装 PyYAML,以便 python-ogre 解释器可以访问它。我成功安装了 PyYAML(安装程序检测到 python 2.7),标准 python 控制台成功导入它,没有任何问题。
然而,python-ogre SDK 解释器抱怨没有该名称的模块。
我完全迷路了。有人可以指出我正确的方向和/或解释发生了什么吗?
预先非常感谢, Blz
编辑 MichaelMior 暗示这可能涉及我的 sys.path。我对 python 很陌生,所以欢迎任何解释。
标准 python 安装的 sys.path 的输出是:
C:\Windows\system32\python27.zip
C:\Python27\lib\site-packages\pip-1.0.2-py.2.7.egg
C:\Python27\DLLs
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
python-ogre SDK 的输出是:
C:\Windows\system32\python27.zip
C:\python-ogre\[SDK]\DLLs
C:\python-ogre\[SDK]\lib
C:\python-ogre\[SDK]\lib\plat-win
C:\python-ogre\[SDK]\lib\lib-tk
C:\python-ogre\[SDK]
C:\python-ogre\[SDK]\lib\site-packages
编辑 2:
好的,我明白了!我刚刚做了 sys.path.append('C:\Python27\lib\site-packages')
显然,第 3 方模块已安装到该目录。这样做安全吗?我是否有造成任何冲突的风险?
I recently downloaded the python-ogre SDK, which appears to include its own python interpreter.
I say "appears" because this interpreter also seems to depend on the standard python 2.7.2 installation. I tried uninstalling the latter, and the python-ogre SDK interpreter complains that python27.dll is missing from my computers.
I really don't understand how the two interpreters are related, and the python-ogre SDK forum topic has been less than helpful.
I really need to instally PyYAML such that the python-ogre interpreter has access to it. I successfully installed PyYAML (the installer detected python 2.7) and the standard python console manages to import it without any issues.
The python-ogre SDK interpreter, however, complains that there is no module by that name.
I'm completely lost. Can someone point me in the right direction and/or explain what is going on?
With many thanks in advance,
Blz
EDIT
MichaelMior hinted at the possibility that this involved my sys.path. I'm rather new to python, so any explanations are welcome.
The output of sys.path for the standard python installation is:
C:\Windows\system32\python27.zip
C:\Python27\lib\site-packages\pip-1.0.2-py.2.7.egg
C:\Python27\DLLs
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
The output of the python-ogre SDK is:
C:\Windows\system32\python27.zip
C:\python-ogre\[SDK]\DLLs
C:\python-ogre\[SDK]\lib
C:\python-ogre\[SDK]\lib\plat-win
C:\python-ogre\[SDK]\lib\lib-tk
C:\python-ogre\[SDK]
C:\python-ogre\[SDK]\lib\site-packages
EDIT 2:
Okay I got it! I just did sys.path.append('C:\Python27\lib\site-packages')
Apparently, 3rd party modules get installed to that directory. Is this safe to do? Do I risk creating any sort of conflicts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个Python解释器都有它的sys.path,它将用来搜索模块。
当您安装 PyYAML 时,它被安装到普通 Python 解释器的目录 (C:\Python27\lib\site-packages)。当你尝试从 python-ogre 导入它时,它不知道去那里,所以它找不到它。这就是将文件夹添加到 sys.path 所做的事情 - 告诉 python-ogre 在该文件夹中查找模块。
Each Python interpreter has its sys.path, which it will use to search for modules.
When you installed PyYAML, it got installed to the directory for the plain Python interpreter (C:\Python27\lib\site-packages). When you try to import it from python-ogre, it has no idea to look there so it can't find it. That's what adding the folder to sys.path did - tell python-ogre to look in that folder for modules.