How to install various Python libraries in Jython?

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

In Jython, how can I install libraries like lxml , Scrappy and BeautifulSoup , which I would normally install via pip or easy_install

+45
java python pip easy-install jython
Jul 22 2018-11-11T00:
source share
4 answers

Some Python modules, such as lxml , have the required components in C. They will not work in Jython.

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

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

 $ jython ez_setup.py 

[Easy_install script will be] installed in the bin directory of the Jython installation ( /home/lsoto/jython2.5.0/bin in the example above). If you often work with Jython, it is a good idea to add this directory to your PATH environment variable, so you do not have to enter it all the time every time you want to use easy_install or other scripts installed in this directory.

Testing it yourself, after installing setuptools in Jython, pip is 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'> >>> 
+34
Jul 22 '11 at 7:45
source share
— -

According to v2.7b4, the Jython distribution includes a provisioning module that simplifies pip and setuptools installation:

 jython -m ensurepip 

Beware of sys.platform == 'win32' issue which will help you use PyPI packages that rely on this method to determine the host platform.

+9
Mar 26 '15 at 10:16
source share

I am Jython, although you have the power of Java libraries, not the limitation of the ability to install multiple C. python libraries.

For example, you'd better use Jsoup instead of Beautiful soup, or go for a complete solution like Jtidy .

Use Jaxp instead of lxml.

Another option that suits your needs: NekoHTML

+7
Jul 22 2018-11-23T00:
source share

I have installed both CPython and Jython. Here is what I do if I want to install the package in Jython via pip.

 jython -m pip install <package_name> 

For example, to install the robot platform in jython (since I want to write keyword libraries in Java), I did

 jython -m pip install robotframework 
0
Apr 03 '18 at 16:49
source share



All Articles