I'm trying to run my GPU:0 as a physical device,but this can be done only with tensorflow <= 2.10 and Jupyter Notebook <= 6.0. But with this dependencies I cannot run some other code as explained below:

I cannot run this command properly:

import h5py
dir(h5py)

It gives

['__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__']

while it should give a much longer list:

['AttributeManager',
 'Dataset',
 'Datatype',
 'Empty',
 'ExternalLink',
 'File',
 'Group',
 'HLObject',
 'HardLink',
 'MultiBlockSlice',
 'Reference',
 'RegionReference',
 'SoftLink',
 'UNLIMITED',
 'VirtualLayout',
 'VirtualSource',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '__version__',
 '_conv',
 '_errors',
 '_hl',
 '_objects',
 '_proxy',
 '_register_converters',
 '_register_lzf',
 '_selector',
 '_unregister_converters',
 '_warn',
 'atexit',
 'check_dtype',
 'check_enum_dtype',
 'check_opaque_dtype',
 'check_ref_dtype',
 'check_string_dtype',
 'check_vlen_dtype',
 'defs',
 'enable_ipython_completer',
 'enum_dtype',
 'filters',
 'get_config',
 'h5',
 'h5a',
 'h5ac',
 'h5d',
 'h5ds',
 'h5f',
 'h5fd',
 'h5g',
 'h5i',
 'h5l',
 'h5o',
 'h5p',
 'h5pl',
 'h5py_warnings',
 'h5r',
 'h5s',
 'h5t',
 'h5z',
 'is_hdf5',
 'opaque_dtype',
 'ref_dtype',
 'regionref_dtype',
 'register_driver',
 'registered_drivers',
 'run_tests',
 'special_dtype',
 'string_dtype',
 'unregister_driver',
 'utils',
 'version',
 'vlen_dtype']

EDIT also with this code it gives a strange error:

import inspect
inspect.getfile(h5py)
print(h5py.__version__)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[195], line 2
      1 import inspect
----> 2 inspect.getfile(h5py)
      3 print(h5py.__version__)

File ~\Documents\myenvGPU3\lib\site-packages\torch\package\package_importer.py:696, in _patched_getfile(object)
    694     if object.__module__ in _package_imported_modules:
    695         return _package_imported_modules[object.__module__].__file__
--> 696 return _orig_getfile(object)

File ~\Documents\myenvGPU3\lib\inspect.py:778, in getfile(object)
    776     if getattr(object, '__file__', None):
    777         return object.__file__
--> 778     raise TypeError('{!r} is a built-in module'.format(object))
    779 if isclass(object):
    780     if hasattr(object, '__module__'):

TypeError: <module 'h5py' (<_frozen_importlib_external._NamespaceLoader object at 0x000001C504CFDF90>)> is a built-in module

EDIT

Bingo: my h5py now runs smoothly. The problem was that I was executing h5py from another environment than was the current one. But this raises another question, how do I make priority to execute C:\Users\Documents\myenvGPU4\lib\ more greedily (i.e. first) than C:\Users\Documents\myenvGPU3\lib\. This didn't solve the problem:

import sys

# Directory you want to add
directory_to_prepend = 'C:\Users\Documents\myenvGPU4\lib\'

# Prepend the directory to sys.path
sys.path.insert(0, directory_to_prepend)

# Verify the change (optional)
print(sys.path)
0

There are 0 best solutions below