名前: | ごうじん
|
---|---|
所属: | フリーランス |
Python歴: | 5年 |
お気に入り: | Tornado, Click |
活動: | tornado-crontab |
$ curl -OL https://repo1.maven.org/maven2/org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar
$ java -jar jython-installer-2.7.1.jar
$ curl -OL https://repo1.maven.org/maven2/org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar
$ java -jar jython-installer-2.7.1.jar \
--console \
--silent \
--type standard \
--directory /path/to/jython
$ curl -OL https://repo1.maven.org/maven2/org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar
$ java -jar jython-installer-2.7.1.jar \
--console \
--silent \
--type standard \
--directory /path/to/jython
Performing silent installation
10 %
20 %
30 %
40 %
50 %
60 %
70 %
80 %
Generating start scripts ...
Installing pip and setuptools
90 %
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.1 setuptools-28.8.0
100 %
Congratulations! You successfully installed Jython 2.7.1 to directory /path/to/jython.
$ java -jar jython-installer-2.7.1.jar \
--console \
--silent \
--type standalone \
--directory /path/to/jython
OR
$ curl -OL https://repo1.maven.org/maven2/org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar
# GUI及びコンソールインストールした場合
$ /path/to/jython/bin/jython [Pythonコードファイル]
# ライブラリとして使う場合
$ java -jar jython-standalone-2.7.1.jar [Pythonコードファイル]
# 対話モード
$ /path/to/jython/bin/jython
※Java9以降を使った場合は、警告が出るが問題なく動く
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by jnr.posix.JavaLibCHelper (file:/path/to/jython/jython.jar) to method sun.nio.ch.SelChImpl.getFD()
WARNING: Please consider reporting this to the maintainers of jnr.posix.JavaLibCHelper
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
# coding: utf-8
import random
VALUES = ['spam', 'ham', 'egg']
def choice():
return random.choice(VALUES)
if __name__ == '__main__':
print choice()
$ /path/to/jython/bin/jython jp.gaujin.py.Simple
spam
package jp.gaujin.java;
import java.util.Random;
public class Simple {
public static final String[] VALUES = { "foo", "bar", "baz" };
private static Random random = new Random();
public static String choice() {
return VALUES[random.nextInt(VALUES.length)];
}
}
from jp.gaujin.java.Simple import choice
if __name__ == '__main__':
print choice()
import org.python.util.PythonInterpreter;
public class Embedded1 {
public static void main(String... args) throws Exception {
PythonInterpreter pi = new PythonInterpreter();
pi.exec(String.join(System.getProperty("line.separator")
, "# coding: utf-8"
, "import random"
, "VALUES = ['spam', 'ham', 'egg']"
, "def choice():"
, " return random.choice(VALUES)"
, "if __name__ == '__main__':"
, " print choice()"
));
}
}
import org.python.util.PythonInterpreter;
public class Embedded1 {
public static void main(String... args) throws Exception {
PythonInterpreter pi = new PythonInterpreter();
pi.exec(String.join(System.getProperty("line.separator")
, "# coding: utf-8"
, "import random"
, "VALUES = ['spam', 'ham', 'egg']"
, "def choice():"
, " return random.choice(VALUES)"
, "if __name__ == '__main__':"
, " print choice()"
));
}
}
# coding: utf-8
import random
VALUES = ['spam', 'ham', 'egg']
def choice():
return random.choice(VALUES)
if __name__ == '__main__':
print choice()
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class Embedded2 {
public static void main(String... args) throws Exception {
PythonInterpreter pi = new PythonInterpreter();
pi.exec(
"from jp.gaujin.py.Simple import choice"
);
PyObject choice = pi.get("choice");
PyObject value = choice.__call__();
System.out.println("value: " + value);
}
}
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class Embedded2 {
public static void main(String... args) throws Exception {
PythonInterpreter pi = new PythonInterpreter();
pi.exec(
"from jp.gaujin.py.Simple import choice"
);
PyObject choice = pi.get("choice");
PyObject value = choice.__call__();
System.out.println("value: " + value);
}
}
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class Embedded2 {
public static void main(String... args) throws Exception {
PythonInterpreter pi = new PythonInterpreter();
pi.exec(
"from jp.gaujin.py.Simple import choice"
);
PyObject choice = pi.get("choice");
PyObject value = choice.__call__();
System.out.println("value: " + value);
}
}
$ /path/to/jython/bin/pip install bottle flask
$ /path/to/jython/bin/pip install django
Collecting django
Using cached https://files.pythonhosted.org/packages/44/e7/872bbf76aa16b7a061698d75325dac023285db33db4bda8ba8fe5d3bb356/Django-1.11.16-py2.py3-none-any.whl
Collecting pytz (from django)
Using cached https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl
Installing collected packages: pytz, django
Successfully installed django-1.11.16 pytz-2018.7
$ /path/to/jython/bin/pip install django-jython
Collecting django-jython
Downloading https://files.pythonhosted.org/packages/7d/e8/f6ec1f54a8364e04d6d27584dec1b74cdf3af62f84651c42ff6b874cbe21/django-jython-1.3.0.tar.gz (175kB)
100% |████████████████████████████████| 184kB 538kB/s
Installing collected packages: django-jython
Running setup.py install for django-jython ... done
Successfully installed django-jython-1.3.0
$ git clone https://github.com/beachmachine/django-jython.git
$ cd django-jython
$ python install setup.py
running install
running bdist_egg
running egg_info
writing dependency_links to django_jython.egg-info/dependency_links.txt
writing top-level names to django_jython.egg-info/top_level.txt
writing django_jython.egg-info/PKG-INFO
:
Installed /path/to/jython/Lib/site-packages/Django-1.8.19-py2.7.egg
Finished processing dependencies for django-jython==1.8.0b4
C言語拡張はできない
バイトエンコーディングファイルがちがう