参照サイト
What is Jython?
To Install Jython as Standalone
インストール手順
######1.Javaバージョンの確認
$ java --version
######2.インストーラーJarのダウンロード
$ wget https://repo1.maven.org/maven2/org/python/jython-installer/2.7.2/jython-installer-2.7.2.jar
$ ls -l
-rw-r--r-- 1 root root 80153928 Mar 22 03:01 jython-installer-2.7.2.jar
######3.ヘッドレスモードでインストーラーを起動する
$ java -jar jython-installer-2.7.2.jar --console
Welcome to Jython !
You are about to install Jython version 2.7.2
(at any time, answer c to cancel the installation)
For the installation process, the following languages are available: English, German
Please select your language [E/g] >>> E
Do you want to read the license agreement now ? [y/N] >>> N
Do you accept the license agreement ? [Y/n] >>> Y
The following installation types are available:
1. All (everything, including sources)
2. Standard (core, library modules, demos and examples, documentation)
3. Minimum (core)
9. Standalone (a single, executable .jar)
Please select the installation type [ 1 /2/3/9] >>> 1
Do you want to exclude parts from the installation ? [y/N] >>> y
The following parts are selectable (n = no more) [mod/demo/doc/src/ensurepip/N] >>> n
Please enter the target directory >>> /usr/local/bin/jython
Unable to find directory /usr/local/bin/jython, create it ? [Y/n] >>> Y
Your java version to start Jython is: Oracle Corporation / 11.0.6
Your operating system version is: Linux / 4.14.173-137.229.amzn2.x86_64
Summary:
- mod: true
- demo: true
- doc: true
- src: true
- ensurepip: true
- JRE: /usr/java/jdk-11.0.6
Please confirm copying of files to directory /usr/local/bin/jython [Y/n] >>> Y
10 %
20 %
30 %
40 %
50 %
60 %
70 %
80 %
Generating start scripts ...
Installing pip and setuptools
90 %
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.io.StreamIO (file:/usr/local/bin/jython/jython.jar) to field java.io.FilterOutputStream.out
WARNING: Please consider reporting this to the maintainers of org.python.core.io.StreamIO
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
DEPRECATION: A future version of pip will drop support for Python 2.7.
Looking in links: /tmp/tmp5hQIoY
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.1 setuptools-41.0.1
100 %
Do you want to show the contents of README ? [y/N] >>> N
Congratulations! You successfully installed Jython 2.7.2 to directory /usr/local/bin/jython.
######4.環境変数を設定する
$ export JYTHON_HOME=/usr/local/bin/jython
$ export PATH=$JYTHON_HOME/bin:$PATH
環境変数を確認する
$ echo $JYTHON_HOME
/usr/local/bin/jython
$ echo $PATH
/usr/local/bin/jython/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
ここまで、Jythonの設定が完了、Jythonのバージョンを確認する
$ jython --version
Jython 2.7.2
######5.Jythonを起動する。
$ jython
Jython 2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:03:58)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java11.0.6
Type "help", "copyright", "credits" or "license" for more information.
>>>
Pythonコードを実行してみる。
>>> from java.lang import System # Java import
>>> print('Running on Java version: ' + System.getProperty('java.version'))
Running on Java version: 11.0.6
>>> print('Unix time from Java: ' + str(System.currentTimeMillis()))
Unix time from Java: 1598423228380
>>>