Personal tools
You are here: Home Forum Use Importing h5py on Salome TUI

Importing h5py on Salome TUI

Up to Use

Importing h5py on Salome TUI

Posted by Moise Rousseau at March 05. 2019

Hi everyone,

I am using Salome as a pre-processor and mesh generator for a subsurface flow simulation named PFLOTRAN (www.pflotran.org). I am writing a Python plugins to export automatically Salome meshes to the right format needed. To do so, I need to create HDF5 file and I would like to use the h5py module.

Unfortunately, I was unable to import the h5py module. I try "import h5py" on the TUI but it return me an "ImportError: No module named 'h5py'". If I try to import the module under a terminal on my computer, it work fine.

Thus, I had to the sys.path list the path to the h5py installation folder ('/home/moise/.local/lib/python3.6/site-packages'), and it seem to find the module. But I got the following error when importing on Salome :

Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/moise/.local/lib/python3.6/site-packages/h5py/__init__.py", line 26, in <module> from . import _errors ImportError: cannot import name '_errors'

I googled this error and it seems to happen when we try to import the module from the install directory : https://stackoverflow.com/questions/36375691/python-jupyter-cannot-import-name-errors-for-h5py

A similar error have been answered here : https://www.salome-platform.org/forum/forum_10/7381901#445101050

Thus, I would like to know if there is an easy way to import the h5py module easily. Can you help me to do so ? If not, how can I bypass this error ? I know I could first export the mesh as DAT and after run the script from my terminal, but I would like Salome to do it automatically.

I am running Salome 9.2.0 on Ubuntu 18.04.

 

Thanks in advance for your help !

M. Rousseau

 

p, li { white-space: pre-wrap; }

Re: Importing h5py on Salome TUI

Posted by Nabil Ghodbane at March 05. 2019

Hi,

you need to install PIP beforehand. Try this solution which was suggested to me:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

SALOME-9.2.0-UB18.04-SRC/salome context

python ./get-pip.py

SALOME-9.2.0-UB18.04-SRC/INSTALL/Python/bin/pip  install h5py

If any issue, let us know.

Re: Importing h5py on Salome TUI

Posted by Moise Rousseau at March 05. 2019

Hi !

Thanks for your help.

I get successfully the get-pip.py script. Unfortunately, I don't know what you want me do to with the "SALOME-9.2.0-UB18.04-SRC/salome context" command. Moreover, when I launch the script "get-pip.py" using the command "exec(open('get-pip.py ').read())" on Salome TUI, it crash without an error message and pip is not installed (i.e. I couldn't import pip on Salome TUI, but I still get pip on my computer running in a terminal). Thus I couln't install h5py for using it on Salome TUI.

Do you actually run h5py on Salome ? Do you experience the same issue ?

Moise

Re: Importing h5py on Salome TUI

Posted by Nabil Ghodbane at March 05. 2019

Hi

the command:

SALOME-9.2.0-UB18.04-SRC/salome context

is aimed to setup your environment such that you point to the Python shipped with SALOME.

 

So just to make sure I understand, can you confirm that you did:

    - start a console (e.g. konsole or xterm)

    -  download get-pip.py: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

   

    - cd to the folder where you unpacked the SALOME-9.2.0-UB18.04-SRC archive (you wrote you use Ubuntu 18.04 archive)

    - execute: SALOME-9.2.0-UB18.04-SRC/salome context

    - execute: python get-pip.py

    - install pip by executing: SALOME-9.2.0-UB18.04-SRC/INSTALL/Python/bin/pip  install h5py

 

 

 

did you do that ?

Re: Importing h5py on Salome TUI

Posted by Moise Rousseau at March 06. 2019

Hi,

I understand better, thank you !

I have download get-pip.py and succesfully setup the Salome environment using SALOME-9.2.0-UB18.04-SRC/salome context.

I got trouble when executing the script "get-pip.py". I got the following error :

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Collecting pip

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/

  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/

  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/

  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/

  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/pip/

  Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping

  Could not find a version that satisfies the requirement pip (from versions: ) No matching distribution found for pip

I try to install PyOpenSSL (https://pypi.org/project/pyOpenSSL/), but it require dependencies, and these dependencies require others dependencies and so on that I need to install manually.

Do you experience the same issue ? Do you have a trick or I should install all dependencies manually ?

Thank again for your help,

Moise

Re: Importing h5py on Salome TUI

Posted by Nabil Ghodbane at March 13. 2019

Hi,

unfortunately the Ubuntu 18 python version misses the ssl module (you can check this by doing import ssl)

Other archives like e.g. Ubuntu 16 or CentOS 7.5 do have pip installed which allows you to install h5py.

 

 

Re: Importing h5py on Salome TUI

Posted by Moise Rousseau at March 18. 2019

Hi Nabil,

Thanks for your help. With it, I manage to successfully install h5py. If you or other person want to do the same, follow the next step :

1. Download the pip and pkgconfig wheel, and h5py source on the following address:

https://pypi.org/project/pip/

https://pypi.org/project/pkgconfig/

https://pypi.org/project/h5py/

2. Copy these new files in the Salome binaries folder

3. Open a terminal in Salome binaries folder and load the salome context with the following command:

./salome context

4. Go (cd command) to the binaries folder:
cd BINARIES-UB18.04/
5. With the pip wheel, install first pkgconfig package and after h5py source (command may change according to the version you want to install):
python pip-19.0.3-py2.py3-none-any.whl/pip install pkgconfig-1.4.0-py2.py3-none-any.whl
python pip-19.0.3-py2.py3-none-any.whl/pip install h5py-2.9.0.tar.gz
6. End. You can check the installation by launching Salome and write the following command in Salome TUI :
import h5py
 
Thanks you again for your help,
Moise

Re: Importing h5py on Salome TUI

Posted by Nabil Ghodbane at March 19. 2019

Hi Moise,

glad to see that you found a workaround to install pip. FYI, this issue is fixed in the next release.

nabil

Re: Importing h5py on Salome TUI

Posted by Moise Rousseau at May 24. 2019

Hi Nabil !

I tested the new release of Salome to import h5py module as you told me the issue would be fixed in the next release. Unfortunately, the h5py module does not import smoothly in Salome TUI. I got the following error when I try the command:

import h5py

Traceback (most recent call last):

File "<input>", line 1, in <module>

File "/home/linux/.local/lib/python3.6/site-packages/h5py/__init__.py", line 26, in <module>

from . import _errors

ImportError: cannot import name '_errors'

p, li { white-space: pre-wrap; }

 

I got also some troubles with the pip package. In a terminal within Salome context, the command pip3 give me the following error:

linux@malartic:~/Program/SALOME-9.3.0-UB18.04-SRC$ pip3

bash: /home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/bin/pip3: /volatile/salome/jenkins/workspace/Salome9_UB18/SALOME-9.3.0-UB18.04/INSTALL/Python/bin/python3.6: bad interpreter: No such file or directory

The above error could be avoided by changing the path of the interpreter. Yet I got another error which I had no more deeply investigated:

linux@malartic:~/Program/SALOME-9.3.0-UB18.04-SRC$ pip3

Traceback (most recent call last):
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/bin/pip3", line 7, in <module>
from pip import main
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/__init__.py", line 43, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
@_call_aside
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
f(*args, **kwargs)
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
dist.activate(replace=False)
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
declare_namespace(pkg)
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
_handle_ns(packageName, path_item)
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'

 

The pip command also gave me another error:

linux@malartic:~/Program/SALOME-9.3.0-UB18.04-SRC$ pip

Traceback (most recent call last):
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/urllib3/lib/python3.6/site-packages/site.py", line 73, in <module>
__boot()
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/urllib3/lib/python3.6/site-packages/site.py", line 3, in __boot
import os
File "/home/linux/Program/SALOME-9.3.0-UB18.04-SRC/BINARIES-UB18.04/Python/lib/python3.6/os.py", line 409
yield from walk(new_path, topdown, onerror, followlinks)
^
SyntaxError: invalid syntax

I just would like to report these issues. I managed to install h5py module with the previous workaround successfully.

Have a nice day,

Moise


p, li { white-space: pre-wrap; }

Re: Importing h5py on Salome TUI

Posted by Nabil Ghodbane at May 27. 2019

Hi Moise,

thanks for your feedback.

python path in pip3 file: the first line of pip3 needs to be changed to:

#!/usr/bin/env python

second issue

: I did not manage to reproduce  it on one Ubuntu 18.04 node, I have access to,

 you can try to rebuild Python on your node:

tar zxvf SALOME-9.3.0-*-SRC.tar.gz

cd SALOME-9.3.0-*-SRC

source ./install_bin.sh

./sat prepare SALOME-9.3.0 -p CONFIGURATION,Python

./sat compile SALOME-9.3.0 -p CONFIGURATION,Python --clean_all

./sat launcher SALOME-9.3.0 -n salome_launcher

./salome_launcher context

pip3 install h5py

Then, test the import:

python -c 'import h5py; print(h5py.__file__)'

Her again, it worked on my Ubunut 18 node.

 

Re: Importing h5py on Salome TUI

Posted by Moise Rousseau at July 03. 2019

Hi Nabil,

Soory for my late answer.

I also test h5py and pip importation on Salome on another computer with Ubuntu 18.04 with the same errors I mentioned earlier. Unfortunately, rebuilding Python as you mention make not things work. When I arrive to "pip3 install h5py" instruction after rebuild, I got an error. You can find below my full terminal output:

a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$ source ./install_bin.sh
copies BINARIES-UB18.04 into INSTALL
does the substitutions
a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$ ./sat prepare SALOME-9.3.0 -p CONFIGURATION,Python
create log dir /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/LOGS
Clean the source directories ...OK
Getting sources of the application SALOME-9.3.0
  workdir = /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/..

CONFIGURATION:         arc:/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/ARCHIVES/CONFIGURATION.tgz ... OK
Python:                arc:/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/ARCHIVES/Python-3.6.5.tar.gz ... OK

Getting sources of the application: OK (2 / 2)
Patching sources of the application SALOME-9.3.0
  workdir = /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/..


Patching sources of the application: OK (2 / 2)
a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$ ./sat compile SALOME-9.3.0 -p CONFIGURATION,Python --clean_all
Executing the compile commands in the build directories of the products of the application SALOME-9.3.0
  SOURCE directory = /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/../SOURCES
   BUILD directory = /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/../BUILD

Compilation of CONFIGURATION ................. ignored                      
Compilation of Python ........................ SCRIPT /home/a351-linux/Program/SCompilation of Python ........................                                                                                                                  Compilation of Python ........................ OK
INSTALL directory = /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/../INSTALL/Python

Compilation: OK (2/2)
a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$ ./sat launcher SALOME-9.3.0 -n salome_launcher
Generating launcher for SALOME-9.3.0 :
  /home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/../salome_launcher
a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$ ./salome_launcher context
***
*** SALOME context is now set.
*** Enter 'exit' (only once!) to leave SALOME context.
***
a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$ pip3 install h5py
Traceback (most recent call last):
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/salomeTools/../INSTALL/Python/bin/pip3", line 7, in <module>
    from pip import main
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/__init__.py", line 43, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/home/a351-linux/Program/SALOME-9.3.0-UB18.04-SRC/INSTALL/Python/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
a351-linux@a351linux-desktop:~/Program/SALOME-9.3.0-UB18.04-SRC$

Have a nice day,

Moise

Powered by Ploneboard
Document Actions