如何在Jython中安装各种Python库?

发布于 2021-01-29 15:06:14

我知道我可以使用Java安装Jython,并且可以在使用Python的地方使用Jython。Jython外壳运行良好。

在Jython中,我该如何安装类似的库lxmlScrappyBeautifulSoup该库通常是通过pip或安装的easy_install

关注者
0
被浏览
104
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    某些Python模块(如)lxml在C中具有必需的组件。它们在Jython中不起作用。

    大多数Python软件包都可以正常运行,您可以使用与CPython相同的工具来安装它们。在Jython
    Book的附录A中
    对此进行了描述

    要获取setuptools,请从http://peak.telecommunity.com/dist/ez_setup.py下载ez_setup.py
    。然后,转到保存下载文件的目录并执行:

    $ jython ez_setup.py
    

    [easy_install脚本将被安装]安装到Jython安装的bin目录中(/home/lsoto/jython2.5.0/bin在上面的示例中)。如果您经常使用Jython,则最好将此目录放在PATH环境变量的前面,这样就不必每次都要使用easy_install或此目录中安装的其他脚本来键入整个路径。

    在Jython中安装setuptools之后,我自己进行了测试,正确安装了pip:

    $ sudo /usr/bin/jython2.5.2b1/bin/easy_install pip
    Searching for pip
    [...]
    Installing pip-2.5 script to /usr/bin/jython2.5.2b1/bin
    Installing pip script to /usr/bin/jython2.5.2b1/bin
    
    Installed /usr/bin/jython2.5.2b1/Lib/site-packages/pip-1.0.2-py2.5.egg
    Processing dependencies for pip
    Finished processing dependencies for pip
    
    $ sudo /usr/bin/jython2.5.2b1/bin/pip install bottle
    Downloading/unpacking bottle
      Downloading bottle-0.9.6.tar.gz (45Kb): 45Kb downloaded
      Running setup.py egg_info for package bottle
        Installing collected packages: bottle
      Running setup.py install for bottle
    Successfully installed bottle
    Cleaning up...
    
    $ jython
    Jython 2.5.2b1 (Release_2_5_2beta1:7075, Jun 28 2010, 07:44:20) 
    [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_26
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import bottle
    >>> bottle
    <module 'bottle' from '/usr/bin/jython2.5.2b1/Lib/site-packages/bottle$py.class'>
    >>>
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看