Many thanks, Daniel & Tõnis, for both of your replies!
The GeoServer 2.11.2 uses Jython-2.5.0.jar that is saved in the "WEB-INF/lib".
I don't know how to install new packages into this jar file so that GeoServer
can use them.
I actually ended up with installing the most recent standalone Jython-2.7.0 on
my computer. I was able to run easy_install or pip off the standalone Jython to
install a couple of packages. Each py file installed for the new packages comes
with a class file. This is different to native Python. I then managed to copy
the resulted package folder to GeoServer's "\scripts\lib\py".
I think this is my only way to install new packages for GeoServer to use. As
said above, I don't know how to install packages to the Jython jar file without
having to use the standalone Jython. Could someone direct me?
In terms of the "requests" package, I am still having trouble installing
through pip or easy_install off the standalone Jython.
C:\jython2.7.0\bin>pip install requestsTraceback (most recent call last): File
"C:\jython2.7.0\Lib\runpy.py", line 161, in _run_module_as_main return
_run_code(code, main_globals, None, File "C:\jython2.7.0\Lib\runpy.py", line
72, in _run_code exec code in run_globals File
"C:\jython2.7.0\bin\pip.exe\__main__.py", line 5, in <module> File
"C:\jython2.7.0\Lib\site-packages\pip\__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog File
"C:\jython2.7.0\Lib\site-packages\pip\util.py", line 17, in <module> from
pip.locations import ( File
"C:\jython2.7.0\Lib\site-packages\pip\locations.py", line 109, in <module>
build_prefix = _get_build_prefix() File
"C:\jython2.7.0\Lib\site-packages\pip\locations.py", line 90, in
_get_build_prefix if file_uid != os.geteuid():AttributeError: 'module'
object has no attribute 'geteuid'
Google search suggested this package does not have a java port... Very weird.
- Daniel, you mentioned that "from Jython we can use Java networking
libraries". Can you elaborate it in details please? How can I use 3rd Java libs
in writing a GeoServer custom app or a web processing service in Python or
JavaScript as I would like to stick with Python/JavaScript?
Cheers,Alex
On Tuesday, 5 September 2017, 4:49:39 pm AEST, Daniel Baird
<[email protected]> wrote:
Alex you should be able to do normal python package installs using jython, e.g.
https://stackoverflow.com/questions/6787015/how-can-i-install-various-python-libraries-in-jython
You use jython to run easy install, then you can jython easy-install pip, then
you can jython pip install whatever you want. You might need to search around a
bit to find the jython that geoserver uses, but it sounds like you've found its
location already.
It won't work for libraries that compile their own binaries, but I think
Requests is pure python so should work fine.
Also, remember from Jython you can use Java networking libraries, so you
mightn't need Requests.
CheersDaniel
On Tue, 5 Sep 2017 at 16:37 Alex Chen via Geoserver-users
<[email protected]> wrote:
Hi Tõnis,
Thanks for the info.
I know the pip way to install new packages on native Python. But GeoServer does
not seem to use the native Python on the OS but Jython in the WEB-INF/lib. I
tried to copy the installed package to "{GEOSERVER_DATA}/scripts/lib/py/" and
restarted GeoServer. I imported the package in the Python script and copied the
file to "{GEOSERVER_DATA}\scripts\apps\hello\main.py". When I called the app
url via HTTP as instructed in the documentation, it complained about "unable to
find the module xxx".
Hope someone could give any clue about it.
Thanks.
Cheers,Alex
On Tuesday, 5 September 2017, 4:22:06 pm AEST, tõnis kärdi
<[email protected]> wrote:
Hey Alex,
You can use e.g pip https://pip.pypa.io/en/stable/ but I guess any
Python package manager will do. With pip it would be smth like:
pip install packagename -t /the/path/you/want
Maybe there's a way through simply setting environment variables
aswell to use your existing modules. But not really sure, I don't know
enough about jython/java for that matter.
All the best,
Tõnis
2017-09-05 3:05 GMT+03:00 Alex Chen <[email protected]>:
> Thanks Tõnis!
>
> Here is the output to the sys.path in my script when run by GeoServer:
>
> ['C:\\geoserver_data\\scripts\\lib\\py', 'C:\\Program Files (x86)\\GeoServer
> 2.11.2\\webapps\\geoserver\\WEB-INF\\lib\\Lib', 'C:\\Program Files
> (x86)\\GeoServer
> 2.11.2\\webapps\\geoserver\\WEB-INF\\lib\\jython-2.7.0.jar\\Lib',
> '__classpath__', '__pyclasspath__/']
>
>
> Obviously the "requests" python library is not contained in any of the paths
> above. So the question is how I can install "requests" so that GeoServer can
> use. The official documentation does not offer any clue in this aspect.
>
> Much appreciated!
>
> Cheers,
> Alex
>
>
> On Monday, 4 September 2017, 8:52:03 pm AEST, tõnis kärdi
> <[email protected]> wrote:
>
>
> Sorry, I meant sys.path :)
>
> Tõnis
>
> 2017-09-04 11:22 GMT+03:00 tõnis kärdi <[email protected]>:
>> Hi Alex,
>>
>> did you check what os.sys.path outputs in a script run by GeoServer?
>> Maybe it's just that requests is not on an importable path?
>>
>> All the best,
>> Tõnis
>>
>> 2017-09-04 4:38 GMT+03:00 Alex Chen via Geoserver-users
>> <[email protected]>:
>>> Dear all,
>>>
>>> I am with GeoServer 2.11.2 and am planning to do some scripting on it.
>>>
>>> I would like to run some custom Python scripts either as Apps that can be
>>> called via http or as WPS services. I have managed to install the scripts
>>> plugin on GeoServer, and the "apps" and "wps" folders are both visible in
>>> the "scripts" parent folder.
>>>
>>> I have tried to save some custom scripts in the apps folder and called
>>> via
>>> http, for instance, "http://localhost:8090/geoserver/script/apps/hello",
>>> but
>>> it failed due to "unable to find packages". Those packages that GeoServer
>>> was unable to find include "requests" and "urllib2" etc but I am pretty
>>> sure
>>> they were both installed properly on the Python. I am wondering how
>>> GeoServer gets to know where the Python (2.7.13) directory is and how
>>> Python
>>> gets utilised by GeoServer on my computer via either http or wps.
>>>
>>> I have posted some questions on stackoverflow, but haven't received much
>>> positive reply.
>>>
>>> Much appreciated!
>>>
>>> Alex
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> Geoserver-users mailing list
>>>
>>> Please make sure you read the following two resources before posting to
>>> this
>>> list:
>>> - Earning your support instead of buying it, but Ian Turton:
>>> http://www.ianturton.com/talks/foss4g.html#/
>>> - The GeoServer user list posting guidelines:
>>> http://geoserver.org/comm/userlist-guidelines.html
>>>
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/geoserver-users
--
@tkardi
skype: tonis.kardi
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org!
http://sdm.link/slashdot_______________________________________________
Geoserver-users mailing list
Please make sure you read the following two resources before posting to this
list:
- Earning your support instead of buying it, but Ian Turton:
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines:
http://geoserver.org/comm/userlist-guidelines.html
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-users mailing list
Please make sure you read the following two resources before posting to this
list:
- Earning your support instead of buying it, but Ian Turton:
http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines:
http://geoserver.org/comm/userlist-guidelines.html
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-users