How To Import A Pip Package Through Jython?
In reference to hooking into PIP from Jython, It looks like, possibly, PIP is included with Jython: How can I install various Python libraries in Jython? Jython easy_install error
Solution 1:
Once Jython 2.7 is installed to ~/
then:
thufir@doge:~$
thufir@doge:~$ jython --version
Jython 2.7.0
thufir@doge:~$
thufir@doge:~$ pip --version
pip 1.6.dev1 from /home/thufir/jython/Lib/site-packages (python 2.7)
thufir@doge:~$
thufir@doge:~$ pip freeze
thufir@doge:~$
thufir@doge:~$ pip install virtualenv
Downloading/unpacking virtualenv
Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB): 1.8MB
downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
thufir@doge:~$
thufir@doge:~$ mkdir nfl
thufir@doge:~$
thufir@doge:~$ cd nfl
thufir@doge:~/nfl$
thufir@doge:~/nfl$ jython -m virtualenv jve
Cannot find file /home/thufir/jython/Include (bad symlink)
New jython executable in /home/thufir/nfl/jve/bin/jython
Installing setuptools, pip, wheel...done.
thufir@doge:~/nfl$
thufir@doge:~/nfl$ . jve/bin/activate
(jve) thufir@doge:~/nfl$
(jve) thufir@doge:~/nfl$ pip install nflgame
Collecting nflgame
/home/thufir/nfl/jve/Lib/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:310:
SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject
Name Indication) extension to TLS is not available on this platform. This
may cause the server to present an incorrect TLS certificate, which can
cause validation failures. You can upgrade to a newer version of Python to
solve this. For more information, see
https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
warnings.warn(
/home/thufir/nfl/jve/Lib/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:115:
InsecurePlatformWarning: A true SSLContext object is not available. This
prevents urllib3 from configuring SSL appropriately and may cause certain
SSL connections to fail. You can upgrade to a newer version of Python to
solve this. For more information, see
https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
warnings.warn(
Downloading nflgame-1.2.20.tar.gz (34.0MB)
100%
|████████████████████████████████|34.0MB 11kB/s
Collecting pytz (from nflgame)
Downloading pytz-2016.10-py2.py3-none-any.whl (483kB)
100%
|████████████████████████████████| 491kB 158kB/s
Collecting httplib2 (from nflgame)
Downloading httplib2-0.10.3.tar.gz (204kB)
100%
|████████████████████████████████| 204kB 136kB/s
Collecting beautifulsoup4 (from nflgame)
Downloading beautifulsoup4-4.5.3-py2-none-any.whl (85kB)
100%
|████████████████████████████████| 92kB 147kB/s
Building wheels for collected packages: nflgame, httplib2
Running setup.py bdist_wheel for nflgame ... done
Stored indirectory:
/home/thufir/.cache/pip/wheels/12/e2/67/97dfa7f48af53140aa18136c8fbf019c455600b00b6cd4f07d
Running setup.py bdist_wheel for httplib2 ... done
Stored indirectory:
/home/thufir/.cache/pip/wheels/ca/ac/5f/749651f7925b231103f5316cacca82a487810c22d30f011c0c
Successfully built nflgame httplib2
Installing collected packages: pytz, httplib2, beautifulsoup4, nflgame
Successfully installed beautifulsoup4-4.5.3 httplib2-0.10.3 nflgame-1.2.20
pytz-2016.10
(jve) thufir@doge:~/nfl$
(jve) thufir@doge:~/nfl$ pip freeze
appdirs==1.4.0
beautifulsoup4==4.5.3
httplib2==0.10.3
nflgame==1.2.20
packaging==16.8
pyparsing==2.1.10
pytz==2016.10
six==1.10.0
(jve) thufir@doge:~/nfl$
and then:
thufir@doge:~/nfl$
thufir@doge:~/nfl$ . jve/bin/activate
(jve) thufir@doge:~/nfl$
(jve) thufir@doge:~/nfl$ jython sample.py
L.McCoy 31 carries for184 yards and1 TDs
T.Pryor 13 carries for112 yards and0 TDs
S.Vereen 14 carries for101 yards and0 TDs
A.Peterson 18 carries for93 yards and2 TDs
R.Bush 21 carries for90 yards and0 TDs
(jve) thufir@doge:~/nfl$
(jve) thufir@doge:~/nfl$ cat sample.py
import nflgame
games = nflgame.games(2013, week=1)
players = nflgame.combine_game_stats(games)
for p in players.rushing().sort('rushing_yds').limit(5):
msg = '%s %d carries for %d yards and %d TDs'
print msg % (p, p.rushing_att, p.rushing_yds, p.rushing_tds)
(jve) thufir@doge:~/nfl$
although it's not strictly necessary to use the virtual env.
Post a Comment for "How To Import A Pip Package Through Jython?"