在Jython 2.7.0上安装networkx 1.9.1

时间:2015-05-18 11:57:15

标签: python-2.7 pip jython networkx jython-2.7

来自官方网络x Version 1.9 notes and API changes

  

为Jython 2.7 [...]添加了基本支持,但它们仍然没有得到官方支持。

如何在Jython上安装networkx?

我尝试了什么:

  • 在我的Ubuntu 14.04 32bit上安装了jython2.7.0。
  • 尝试通过pip安装networkx:

sudo /opt/jython2.7.0/bin/pip install networkx

下载了文件networkx-1.9.1-py2.py3-none-any.whl,但在某些时候出错:

Exception:
Traceback (most recent call last):
  File "/opt/jython2.7.0/Lib/site-packages/pip/basecommand.py", line 133, in main
    status = self.run(options, args)
  File "/opt/jython2.7.0/Lib/site-packages/pip/commands/install.py", line 325, in run
    requirement_set.install(
  File "/opt/jython2.7.0/Lib/site-packages/pip/commands/install.py", line 325, in run
    requirement_set.install(
  File "/opt/jython2.7.0/Lib/site-packages/pip/req/req_set.py", line 633, in install
    requirement.install(
  File "/opt/jython2.7.0/Lib/site-packages/pip/req/req_install.py", line 719, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/opt/jython2.7.0/Lib/site-packages/pip/req/req_install.py", line 990, in move_wheel_files
    move_wheel_files(
  File "/opt/jython2.7.0/Lib/site-packages/pip/wheel.py", line 154, in move_wheel_files
    compileall.compile_dir(source, force=True, quiet=True)
  File "/opt/jython2.7.0/Lib/compileall.py", line 56, in compile_dir
    if not compile_dir(fullname, maxlevels - 1, dfile, force, rx,
  File "/opt/jython2.7.0/Lib/compileall.py", line 56, in compile_dir
    if not compile_dir(fullname, maxlevels - 1, dfile, force, rx,
  File "/opt/jython2.7.0/Lib/compileall.py", line 50, in compile_dir
    if not compile_file(fullname, ddir, force, rx, quiet):
  File "/opt/jython2.7.0/Lib/compileall.py", line 99, in compile_file
    ok = py_compile.compile(fullname, None, dfile, True)
  File "/opt/jython2.7.0/Lib/compileall.py", line 99, in compile_file
    ok = py_compile.compile(fullname, None, dfile, True)
  File "/opt/jython2.7.0/Lib/py_compile.py", line 99, in compile
    _py_compile.compile(file, cfile, dfile)
  File "/opt/jython2.7.0/Lib/py_compile.py", line 99, in compile
    _py_compile.compile(file, cfile, dfile)
RuntimeException: java.lang.RuntimeException: Method code too large!

我在_py_compile.compile(file, cfile, dfile)函数之前添加了以下print语句:

print "file: %s" % file
print "cfile: %s" % cfile
print "dfile: %s" % dfile

给了我:

file: /tmp/pip_build_vagrant/networkx/networkx/generators/atlas.py
cfile: None
dfile: None

有没有人设法在Jython2.7.0上安装networkx 1.9?

1 个答案:

答案 0 :(得分:4)

以下是如何在Jython中安装networkx:

  1. 转到PyPI并下载networkx source package
  2. 将networkx源解压缩到一个文件夹中。
  3. 在源文件夹中,删除文件networkx/generators/atlas.py(这是Jython无法解析的文件。无论如何它在Jython中都不起作用,所以只需删除它。)
  4. 文件networkx/readwrite/gml.py中的
  5. ,删除了lib2to3的所有提及(由于Jython中的当前错误,lib2to3不可用):

    • 在第44-46行,注释掉lib2to3的导入
    • 在75左右的行上,更改:

      rtp_fix_unicode = RefactoringTool(['lib2to3.fixes.fix_unicode'], 
                                        {'print_function': True})
      

      为:

      rtp_fix_unicode = None
      
    • 在第145行附近,在try-except语句中,删除ParseError和TokenError。
  6. 返回源文件夹,然后运行:

    jython/pip install .
    

    或者,如果你没有jython的pip:

    jython setup.py install
    
  7. 它应该成功安装,你现在应该能够在Jython中导入networkx。