I can see that the viewer_config.py file from itkwidgets points to the ITK_VIEWER_SRC location. I have cloned itkwidgets locally and created a local version of the package (python -m pip -e .) which means I can edit itkwidgets as required. I have tried pointing the ITK_VIEWER_SRC to my local folder but that is not working. How do I tell itkwidgets to use my local itk-vtk-viewer code instead of that at ITK_VIEWER_SRC = ("https://bafybeidadaazleqcepkcofenl5vvnf6uod6tjqvlkoj2ceynhbyzkku5hu.on.fleek.co/")
I have stepped back a number of versions due to a known bug - which results in the current version of itkwidgets not working for me.
Using itkwidgets v0.32.0
To review:
I am trying to edit files (js) within itk-vtk-viewerproject which are called by itkwidgets in Python, however I am unable to determine the steps to be able to do so. I am looking to add some functionality to the itkwidgets package by updating the annotations returned by some function calls within the itk-vtk-viewerjs files.
I have forked itkwidgets from git and installed locally using python -m pip install -e .. I can import this package in my notebook and have confirmed that it is loaded and working as expected.
My expectation is that I should be able to point the package (itkwidgets) towards a local version of the js project (itk-vtk-viewer) so that any edits made can be observed in the notebook.
(Part I do not understand)
In a viewer.js file (itkwidgets) it specifies the location of the js code that I want to edit:
import createViewer from 'itk-vtk-viewer/src/createViewer'
This viewer.js file is pointed to in a index.js file:
and this index.js file is pointed to within the package.json file.
My original thoughts were that I should be able to change the location pointed to in viewer.js file to a local folder and it would point towards the new code. However, even if I change the line to import createViewer from '/<NON_EXISTENT_FOLDER>/src/createViewer'. The code still runs as before. If I point towards the local version, I would expect some added console.log’s to be printed, but again this does not occur.
I have tried reinstalling the package using pip following the change but that did not help either.
@PaulHax Sorry, now it was my turn to miss your tag!
I appreciate this help, but as specified in my latest post above, I have to use itkwidgets v0.32.0 due to a known bug which restricts me being able to use the latest version.
Within v0.32.0, the method to link to itk-vtk-viewer is different.
I then try to install the itkwidgets package in dev mode
python -m pip install -e . from the parent directory
Outputs
The linking of the module seems to work as I can see it in the list if I call check_call(['ls','node_modules'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) following the linking.
Also, when it is not added I get the following error in the output of python -m pip install -e .:
ERROR in ./lib/viewer.js Module not found: Error: Can't resolve 'itk-vtk-viewer/src/createViewer' in '/.../itkwidgets/js/lib'
However, am getting an error specifying:
rebuilding js and css failed missing files: ['/.../itkwidgets/itkwidgets/static/index.js']
This file is indeed not there. The only file created within static folder is extension.js
By the looks of it, it is not created due to other errors of Modules not found, for example
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
How do I load these modules? (@thewtex, Any input here?)
Please find a snippet of the output below (apologies for the length)
Error Message
…
itkwidgets@0.32.0 build
webpack --mode production -p
ERROR in /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js 12:18-74
@ /.../itk-vtk-viewer/src/UserInterface/Image/createLabelMapColorWidget.js
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
ERROR in /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js 12:18-74
@ /.../itk-vtk-viewer/src/UserInterface/Image/createColorRangeInput.js
@ /.../itk-vtk-viewer/src/UserInterface/createImageUI.js
@ /.../itk-vtk-viewer/src/UserInterface/index.js
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
ERROR in /.../itk-vtk-viewer/src/ViewerStore.js
Module not found: Error: Can't resolve 'eventemitter3' in '/.../itk-vtk-viewer/src'
@ /.../itk-vtk-viewer/src/ViewerStore.js 24:43-67
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
ERROR in /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js
Module not found: Error: Can't resolve 'mousetrap' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js 10:40-60
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
Child worker:
2 assets
Entrypoint main = e2e5b834a5dc5a56c944.worker.js e2e5b834a5dc5a56c944.worker.js.map
5 modules
Child
Hash: 0817ccd06068362b3f63
Time: 67725ms
Built at: 28/02/2023 10:22:31
3 assets
Entrypoint main = index.js index.js.map
[34] (webpack)/buildin/global.js 723 bytes {0} [built]
[58] external "@jupyter-widgets/base" 42 bytes {0} [built]
[81] /.../itk-vtk-viewer/src/Rendering/updateGradientOpacity.js 1.36 KiB {0} [built]
[83] /.../itk-vtk-viewer/src/UserInterface/hex2rgb.js 375 bytes {0} [built]
[85] /.../itk-vtk-viewer/src/Rendering/updateLabelMapPiecewiseFunction.js 1.89 KiB {0} [built]
[87] ./lib/index.js 694 bytes {0} [built]
[88] ./lib/viewer.js 71.1 KiB {0} [built]
[148] /.../itk-vtk-viewer/src/Rendering/updateVolumeProperties.js 1.87 KiB {0} [built]
[149] /.../itk-vtk-viewer/src/UserInterface/Image/updateTransferFunctionWidget.js 1.31 KiB {0} [built]
[161] /.../itk-vtk-viewer/src/Rendering/updateLabelMapComponentWeight.js 1.16 KiB {0} [built]
[173] ./lib/itkConfigCDN.js 114 bytes {0} [built]
[174] ./lib/embed.js 399 bytes {0} [built]
[215] /.../itk-vtk-viewer/src/createViewer.js 34.2 KiB {0} [built]
[469] ./lib/lineProfiler.js 6.27 KiB {0} [built]
[470] ./package.json 1.95 KiB {0} [built]
+ 456 hidden modules
ERROR in /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js 12:18-74
@ /.../itk-vtk-viewer/src/UserInterface/Image/createLabelMapColorWidget.js
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/embed.js
ERROR in /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js 12:18-74
@ /.../itk-vtk-viewer/src/UserInterface/Image/createColorRangeInput.js
@ /.../itk-vtk-viewer/src/UserInterface/createImageUI.js
@ /.../itk-vtk-viewer/src/UserInterface/index.js
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/embed.js
ERROR in /.../itk-vtk-viewer/src/ViewerStore.js
Module not found: Error: Can't resolve 'eventemitter3' in '/.../itk-vtk-viewer/src'
@ /.../itk-vtk-viewer/src/ViewerStore.js 24:43-67
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/embed.js
ERROR in /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js
Module not found: Error: Can't resolve 'mousetrap' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js 10:40-60
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/embed.js
Child worker:
2 assets
Entrypoint main = a6481b1cabc91a7ecac9.worker.js a6481b1cabc91a7ecac9.worker.js.map
5 modules
Child
Hash: 8bd9ee9b1faba8410a05
Time: 62803ms
Built at: 28/02/2023 10:22:26
3 assets
Entrypoint main = labextension.js labextension.js.map
[0] external "@babel/runtime/helpers/interopRequireDefault" 42 bytes {0} [built]
[2] external "@babel/runtime/helpers/defineProperty" 42 bytes {0} [built]
[3] external "@babel/runtime/helpers/interopRequireWildcard" 42 bytes {0} [built]
[6] external "mobx" 42 bytes {0} [built]
[7] external "@babel/runtime/helpers/toConsumableArray" 42 bytes {0} [built]
[35] external "@babel/runtime/regenerator" 42 bytes {0} [built]
[36] external "@babel/runtime/helpers/asyncToGenerator" 42 bytes {0} [built]
[79] external "@jupyter-widgets/base" 42 bytes {0} [built]
[80] ./lib/index.js 694 bytes {0} [built]
[81] ./lib/viewer.js 71.1 KiB {0} [built]
[82] external "jupyter-dataserializers" 42 bytes {0} [built]
[144] ./lib/extension-jupyterlab.js 406 bytes {0} [built]
[150] /.../itk-vtk-viewer/src/createViewer.js 34.2 KiB {0} [built]
[386] ./lib/lineProfiler.js 6.27 KiB {0} [built]
[387] ./package.json 1.95 KiB {0} [built]
+ 373 hidden modules
ERROR in /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js 12:18-74
@ /.../itk-vtk-viewer/src/UserInterface/Image/createLabelMapColorWidget.js
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/extension-jupyterlab.js
ERROR in /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js
Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js 12:18-74
@ /.../itk-vtk-viewer/src/UserInterface/Image/createColorRangeInput.js
@ /.../itk-vtk-viewer/src/UserInterface/createImageUI.js
@ /.../itk-vtk-viewer/src/UserInterface/index.js
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/extension-jupyterlab.js
ERROR in /.../itk-vtk-viewer/src/ViewerStore.js
Module not found: Error: Can't resolve 'eventemitter3' in '/.../itk-vtk-viewer/src'
@ /.../itk-vtk-viewer/src/ViewerStore.js 24:43-67
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/extension-jupyterlab.js
ERROR in /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js
Module not found: Error: Can't resolve 'mousetrap' in '/.../itk-vtk-viewer/src/UserInterface'
@ /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js 10:40-60
@ /.../itk-vtk-viewer/src/createViewer.js
@ ./lib/viewer.js
@ ./lib/index.js
@ ./lib/extension-jupyterlab.js
Child worker:
2 assets
Entrypoint main = a6481b1cabc91a7ecac9.worker.js a6481b1cabc91a7ecac9.worker.js.map
5 modules
rebuilding js and css failed
missing files: ['/.../itkwidgets/itkwidgets/static/index.js']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/.../itkwidgets/setup.py", line 212, in <module>
setup(**setup_args)
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
return distutils.core.setup(**attrs)
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 148, in setup
return run_commands(dist)
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
dist.run_commands()
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
self.run_command(cmd)
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/dist.py", line 1214, in run_command
super().run_command(command)
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/.../itkwidgets/setup.py", line 49, in run
raise e
File "/.../itkwidgets/setup.py", line 42, in run
self.distribution.run_command('jsdeps')
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/dist.py", line 1214, in run_command
super().run_command(command)
File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
cmd_obj.run()
File "/.../itkwidgets/setup.py", line 120, in run
check_call([npmName, 'run', 'build'], cwd=node_root,
File "/.../opt/anaconda3/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['npm', 'run', 'build']' returned non-zero exit status 2.
----------------------------------------
WARNING: Discarding file:///…/itkwidgets. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Any help here would be appreciated
Additional Notes:
python -m pip install -e . works sucessfully if I just build itkwidgets without amending or linking itk-vtk-viewer
static folder now contains index.js (plus other files)
Using install rather than link:
npm install /.../itk-vtk-viewer --save
Updates the package.json and package-lock.json files
Then tried python -m pip install -e .
That seems to work as well (builds without errors anyway)
But only if I have run it without any changes, as stated above, first. Otherwise get same error as with link