如何在 Jython 中安装各种 Python 库? [英] How can I install various Python libraries in Jython?

查看:41
本文介绍了如何在 Jython 中安装各种 Python 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用 Java 安装 Jython,并且可以在使用 Python 的地方使用 Jython.Jython shell 工作正常.

I know that I can install Jython with Java and that I can use Jython where I use Python. The Jython shell is working fine.

在 Jython 中,我如何安装像 lxmlScrappyBeautifulSoup 这样的库,我通常通过 pip<安装这些库/code> 或 easy_install

In Jython, how can I install libraries like lxml, Scrappy and BeautifulSoup that I'd normally install via pip or easy_install

推荐答案

某些 Python 模块,例如 lxml,需要使用 C 编写的组件.这些组件在 Jython 中不起作用.

Some Python modules, like lxml, have required components in C. These won't work in Jython.

大多数 Python 包都可以正常工作,您可以使用在 CPython 中使用的相同工具安装它们.这是Jython Book 附录 A 中的描述:

Most Python packages will work fine, and you can install them using the same tools as you use in CPython. This is described in Appendix A of Jython Book:

要获取 setuptools,请从以下位置下载 ez_setup.pyhttp://peak.telecommunity.com/dist/ez_setup.py.然后,前往保存下载文件并执行的目录:

To get setuptools, download ez_setup.py from http://peak.telecommunity.com/dist/ez_setup.py. Then, go to the directory where you left the downloaded file and execute:

$ jython ez_setup.py

[easy_install 脚本将]安装到Jython 安装(示例中的 /home/lsoto/jython2.5.0/bin以上).如果您经常使用 Jython,那么最好将此目录添加到 PATH 环境变量中,这样您就不会每次要使用 easy_install 或安装到此目录的其他脚本.

[The easy_install script will be] installed to the bin directory of the Jython installation (/home/lsoto/jython2.5.0/bin in the example above). If you work frequently with Jython, it’s a good idea to prepend this directory to the PATH environment variable, so you don’t have to type the whole path each time you want to use easy_install or other scripts installed to this directory.

自己测试,在Jython中安装setuptools后,pip安装正确:

Testing it myself, after installing setuptools in Jython, pip installed correctly:

$ 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'>
>>>

这篇关于如何在 Jython 中安装各种 Python 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆