Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import metview #19

Closed
Tsironisa opened this issue Nov 27, 2020 · 10 comments
Closed

import metview #19

Tsironisa opened this issue Nov 27, 2020 · 10 comments

Comments

@Tsironisa
Copy link

Hi i am new to metview.
i installed latest metview release,anacoda and insteall metview 1.5.
but i cant import metview at jupiter

i type
import metview as mv
but i get

Exception: Command "metview" did not respond within 8 seconds. This timeout is configurable by setting environment variable METVIEW_PYTHON_START_TIMEOUT in seconds. At least Metview 5 is required, so please ensure it is in your PATH, as earlier versions will not work with the Python interface.

any help would be appreciated cause i am quite new to this

@iainrussell
Copy link
Member

Hi @Tsironisa,

I think you've probably installed the Metview Python bindings through pip (pip install metview) but have not installed the binaries. If you're in a conda environment, you need to additionally do either this:
conda install metview -c conda-forge
or
conda install metview-batch -c conda-forge
The difference between them is that metview-batch contains all you need to run Metview from Jupyter, and is fairly lightweight in terms of installation, and 'metview' contains additionally a desktop user interface, so you can type 'metview' from the command line and you'll get an interactive desktop environment where you can run Python scripts or just use data and plotting definitions via drag-and-drop with custom editors (see https://confluence.ecmwf.int/display/METV to know what it looks like). This version brings in the Qt library, which is a heavier download.

I hope this helps!
Cheers,
Iain

@Tsironisa
Copy link
Author

Thank you for your time
i try and hope it works,
Best regards
Apostolis

@iainrussell
Copy link
Member

This has been open for a while without comment, so I'll close it - please feel free to open another issue if you still have problems!
Iain

@eyneill777
Copy link

@iainrussell I believe I have discovered that this problem is due to something else besides not installing the binaries. I am trying to run metview on Ubuntu 20.04.2.0, not through Anaconda. My first step was to install the community binary with apt-get, then install the Python bindings through pip. Both of those completed successfully.

However when I try to import the metview package in python (same as what the user above posted) I get the same error as them. However they left out the crucial part. This is the full error text:

python3 Process_grib_to_npy.py
sed: can't read /usr/share/metview/share/metview/app-defaults/Metview: No such file or directory
Traceback (most recent call last):
File "Process_grib_to_npy.py", line 2, in
import metview as mv
File "/home/eron/.local/lib/python3.8/site-packages/metview/init.py", line 26, in
from . import bindings as _bindings
File "/home/eron/.local/lib/python3.8/site-packages/metview/bindings.py", line 175, in
mi = MetviewInvoker()
File "/home/eron/.local/lib/python3.8/site-packages/metview/bindings.py", line 103, in init
raise Exception(
Exception: Command "metview" did not respond within 8 seconds. This timeout is configurable by setting environment variable METVIEW_PYTHON_START_TIMEOUT in seconds. At least Metview 5 is required, so please ensure it is in your PATH, as earlier versions will not work with the Python interface.

Its not timing out because the binaries aren't installed, its timing out because its trying to start them from a path that doesn't exist. When I go into the directory and look I can get as far as /usr/share/metview, but inside of that there is a folder called app-defaults, but not a folder called share. It seems like the "share/metview" part of the path was duplicated for some reason, but doesn't exist on the filesystem.

So my next step was to dig into the python bindings and figure out where the path was defined, and it turned out not to be a problem with the python bindings at all. I traced trough the bindings to the line that was calling the metview startup command "metview" and tried running that manually in the console, which returned the following error:

/usr/bin/metview: line 850: metview_create_user_dir: No such file or directory
metview: EXIT on ERROR (line 1), exit status 1, starting 'cleanup'
/usr/bin/metview: line 152: 5: Bad file descriptor

So I began digging through the metview startup script in that location and found the line of code where the path duplication occurs. But the problem is I don't understand why, and I am hesitant to truncate it and mess with things I don't understand. The duplication occurs on line 541 and 542:

METVIEW_DIR=$INSTALLDIR
METVIEW_DIR_SHARE=${METVIEW_DIR}/share/metview

The value of $INSTALLDIR is already "usr/share/metview", so when that is concatenated onto it the path becomes "usr/share/metview/share/metview". But I don't understand what the share variable is for, or if it would be okay to simply remove that concatenation and set it equal to $METVIEW_DIR.

Any insight you have is appreciated, I know this was a very long comment on a closed post but I feel like I am running into a legitimate installation bug, or I have a fundamental misunderstanding of how this works. Thank you!

@iainrussell
Copy link
Member

Hi @eyneill777 ,

Thanks for the extra information.

OK, I've installed an Ubuntu virtual machine and installed the community-built Metview. I can see there are some issues there! The issues really come because in places we assume that our software packages are installed completely in one place. But on Ubuntu, they have been split, e.g. into metview and metview-data, which are parts of the same package, but are installed into different places. I can see that we can make some small changes on the Metview side that would almost make it work, but the Ubuntu package maintainer will likely have to make a change as well.

But in the meantime, I can show you how I got it to work (I only tested the user interface so far, not Python). Here are the changes I made to the metview startup script:

iain@iain-VirtualBox:/usr/bin$ diff metview.old metview
542c542
< METVIEW_DIR_SHARE=${METVIEW_DIR}/share/metview
---
> METVIEW_DIR_SHARE=/usr/share/metview
543a544
>         METVIEW_BIN=/usr/lib/x86_64-linux-gnu/metview
547c548
<
---
> echo "METVIEW_DIR=$METVIEW_DIR"
682c683,684
< export GRIB_DEFINITION_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/definitions:/usr/lib/./share/eccodes/definitions"
---
> #export GRIB_DEFINITION_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/#definitions:/usr/lib/./share/eccodes/definitions"
> export GRIB_DEFINITION_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/definitions:/usr/lib/../share/eccodes/definitions"
850c852
<    . metview_create_user_dir "$METVIEW_USER_DIRECTORY"
---
>    . $METVIEW_BIN/metview_create_user_dir "$METVIEW_USER_DIRECTORY"

And this is the change I made to the script '/usr/lib/x86_64-linux-gnu/metview/metview_create_user_dir' (simply commented out a line - in fact it is looking for files that should be there in a normal installation, but I can make the next version more forgiving!)

if [ -d $USER_SOURCE_DIR ]
then
   cp -r $USER_SOURCE_DIR/* $USER_DIR
   #cp $USER_SOURCE_DIR/._mv* $USER_DIR

I hope this helps you to get further! Whilst I cannot guarantee that the next Ubuntu release will work out of the box, it should at least be easier to patch :)

Best regards,
Iain

@iainrussell
Copy link
Member

Oh, and also in metview_create_user_dir I changed

USER_SOURCE_DIR=$METVIEW_DIR/share/metview/app-defaults/UserDir

to

USER_SOURCE_DIR=$METVIEW_DIR_SHARE/app-defaults/UserDir

@eyneill777
Copy link

Thanks for the quick response! I was able to get it to work for what I needed (grib functions through python) late last night and forgot to post an update. If you would like I can post the file with the edits I made but it seems like you know what needs to happen and my edits are probably far too hacky to be useful. Let me know if you want it though.

Thanks again!

@iainrussell
Copy link
Member

Thanks for letting me know! I've made some changes on our side, but I think that other changes will be needed from the Ubuntu package maintainer. I'll see if I can help make that happen.

@aasdelat
Copy link

aasdelat commented Feb 24, 2022

Thanks for this post. I solved the problem thanks to this, but with more global changes thak I think can meke it work better:
At the top of the script, change the line:
METVIEW_BIN=/usr/lib//metview
to:
METVIEW_BIN=/usr/lib/x86_64-linux-gnu/metview #/usr/lib//metview

Also, the line:
INSTALLDIR=/share/metview
to:
INSTALLDIR=/usr #/share/metview

The rest of changes are the same as @iainrussell propossed:
Around line 680:
# export GRIB_DEFINITION_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/definitions:/usr/lib/./share/eccodes/definitions"
export GRIB_DEFINITION_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/definitions:/usr/lib/../share/eccodes/definitions"
# export GRIB_SAMPLES_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/samples:/usr/lib/./share/eccodes/samples"
export GRIB_SAMPLES_PATH="${METVIEW_DIR_SHARE}/etc/grib_def/samples:/usr/lib/../share/eccodes/samples"
Note that I have also added a correction for the samples directory.

Around line 850:
# metview_create_user_dir "$METVIEW_USER_DIRECTORY"
. $METVIEW_BIN/metview_create_user_dir "$METVIEW_USER_DIRECTORY"

Hope this helps other people and also to improve the package.

@jpmacveigh
Copy link

Hello,
Does anybody know how to install and use magics-python on a Google Colab ?
Thank's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants