2

来自官方 networkx 1.9 版本的注释和 API 更改

为 Jython 2.7 [...] 添加了基本支持,尽管它们仍未得到官方支持。

如何在 Jython 上安装 networkx?

我试过的:

  • 在我的 Ubuntu 14.04 32 位上安装了 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 "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 吗?

4

1 回答 1

4

Here's how to get networkx installed in Jython:

  1. Go to PyPI and download the networkx source package.
  2. extract the networkx source into a folder.
  3. in the source folder, delete the file networkx/generators/atlas.py (this is the file that's too large for Jython to parse. It doesn't work in Jython anyways, so just delete it).
  4. in the file networkx/readwrite/gml.py, remove all mentions of lib2to3 (due to a current bug in Jython, lib2to3 is not available):

    • on lines 44-46, comment out imports from lib2to3
    • on lines around 75, change:

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

      to:

      rtp_fix_unicode = None
      
    • around line 145, in the try-except statement, remove ParseError and TokenError.
  5. go back to the source folder, and run:

    jython/pip install .
    

    Or alternatively, if you don't have pip for jython:

    jython setup.py install
    

It should install successfully, and you should be able to import networkx in Jython now.

于 2015-07-15T19:06:46.897 回答