问题描述
我是Python的新手.我想尝试看看Pyomo(用于数学建模的Python包)是否可以在IronPython下工作,因为我生成Pyomo所需数据的所有代码都是C#.
I am a complete newbie at Python. I wanted to try to see if Pyomo (a Python package for mathematical modeling) could work under IronPython because all my code for generating the data needed for Pyomo is in C#.
我安装了IronPython 2.7.5,然后以管理员身份尝试了 http://blog.ironpython.net/2014/12/pip-in-ironpython-275.html#disqus_thread 关于如何为IronPython运行"pip".我使用了他们给出的确切示例(安装 html5lib ):
I installed IronPython 2.7.5, then tried as an administrator the advice found in http://blog.ironpython.net/2014/12/pip-in-ironpython-275.html#disqus_thread on how to run "pip" for IronPython. I used the exact example they gave (installing html5lib):
ipy -X:Frames -m ensure pip
ipy -X:Frames -m pip install html5lib
第一行有效,我在Lib/site-packages目录中看到一个名为pip-6.1.1-py2.7.egg
的文件夹,其中包含许多python代码.
The first line worked, and I see in the Lib/site-packages directory a folder called pip-6.1.1-py2.7.egg
with lots of python code in it.
对于第二行,我收到了错误:
For the second line, I received the error:
Unhandled exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 170, in run_module
File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 111, in _get_module_details
ImportError: No module named urllib; 'pip' is a package and cannot be directly executed
在这一点上,我被困住了.任何帮助将不胜感激.
At this point, I'm stuck. Any help would be appreciated.
只要有帮助,打印出sys.version
即可:
Just in case this helps, printing out the sys.version
gives:
2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.34209 (32-bit))
推荐答案
我遇到了同样的问题.看来IronPython无法处理更新版本的pip.我所做的是:
I encountered the same problem. It seems that IronPython can't deal with more recent versions of pip. What I did was:
- 从IronPython的
Lib\site-packages
文件夹中删除pip和setuptools中的所有跟踪记录 - 从命令行运行:
ipy.exe -X:Frames -m ensurepip
- 这安装了IronPython可以理解的pip的旧版本.通过检查文件夹
pip-1.5.6.dist-info
是否出现在IronPython的Lib/site-packages
中进行验证
- remove all traces from pip and setuptools from IronPython's
Lib\site-packages
folder - run from a commandline:
ipy.exe -X:Frames -m ensurepip
- this installed an old version of pip, one that IronPython understands. Verify this by checking that a folder
pip-1.5.6.dist-info
appears in IronPython'sLib/site-packages
故事的道德;使用IronPython时不要升级到较新的pip版本
Moral of the story; don't upgrade to a newer pip version when using IronPython
这篇关于为什么IronPython告诉我pip是一个包而不是可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!