Circular import error
NickNick opened this issue · comments
I was eager to have found pydicom.pixel_data_handlers.pylibjpeg_handler.generate_frames
, so I installed this package to enable it. However, similar to #56, I have the following error after pip install --user pylibjpeg
:
> python -m pydicom.env_info
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/__init__.py", line 32, in <module>
from pydicom.dataelem import DataElement
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/dataelem.py", line 18, in <module>
from pydicom import config # don't import datetime_conversion directly
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/config.py", line 258, in <module>
import pydicom.pixel_data_handlers.rle_handler as rle_handler # noqa
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/pixel_data_handlers/rle_handler.py", line 51, in <module>
from pydicom.encoders.native import _encode_frame
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/encoders/__init__.py", line 1, in <module>
from pydicom.encoders.base import get_encoder, RLELosslessEncoder
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/encoders/base.py", line 869, in <module>
RLELosslessEncoder.add_plugin(
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/encoders/base.py", line 84, in add_plugin
module = import_module(import_path[0])
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/nick/.local/lib/python3.10/site-packages/pydicom/encoders/pylibjpeg.py", line 9, in <module>
from pylibjpeg.utils import get_pixel_data_encoders
File "/home/nick/.local/lib/python3.10/site-packages/pylibjpeg/__init__.py", line 38, in <module>
add_handler()
File "/home/nick/.local/lib/python3.10/site-packages/pylibjpeg/utils.py", line 24, in add_handler
if handler not in pydicom.config.pixel_data_handlers:
AttributeError: partially initialized module 'pydicom' has no attribute 'config' (most likely due to a circular import)
Without pylibjpeg
installed I get
> python -m pydicom.env_info
module | version
------ | -------
platform | Linux-5.15.12-arch1-1-x86_64-with-glibc2.33
Python | 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0]
pydicom | 2.2.2
gdcm | _module not found_
jpeg_ls | _module not found_
numpy | 1.21.5
PIL | 8.4.0
pylibjpeg | _module not found_
openjpeg | _module not found_
libjpeg | _module not found_
The installed version of pylibjpeg prints some errors (but does complete):
> pip install --user pylibjpeg
Collecting pylibjpeg
Using cached pylibjpeg-1.3.0-py3-none-any.whl (28 kB)
Collecting pylibjpeg-openjpeg
Using cached pylibjpeg-openjpeg-1.1.1.tar.gz (2.3 MB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_1baf7583772949f5b35b846de98cee56/setup.py'"'"'; __file__='"'"'/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_1baf7583772949f5b35b846de98cee56/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-0prroz49
cwd: /tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_1baf7583772949f5b35b846de98cee56/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_1baf7583772949f5b35b846de98cee56/setup.py", line 87, in <module>
setup_oj()
File "/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_1baf7583772949f5b35b846de98cee56/setup.py", line 60, in setup_oj
shutil.copy(
File "/usr/lib/python3.10/shutil.py", line 417, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.10/shutil.py", line 254, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'build_tools/cmake/CMakeLists.txt'
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/71/e9/94f3d009e9f9f31bb76075641214bdabdbe557b26ce74ff71ef1c28b2c05/pylibjpeg-openjpeg-1.1.1.tar.gz#sha256=e7adfd8e2c63661b75219d5ae381ac50381054df41ca94d0d01ddfbe362a66cc (from https://pypi.org/simple/pylibjpeg-openjpeg/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Using cached pylibjpeg-openjpeg-1.1.0.tar.gz (2.3 MB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_aa94277196914aa0977c3af9a91bdadd/setup.py'"'"'; __file__='"'"'/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_aa94277196914aa0977c3af9a91bdadd/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-l4_vjocc
cwd: /tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_aa94277196914aa0977c3af9a91bdadd/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_aa94277196914aa0977c3af9a91bdadd/setup.py", line 87, in <module>
setup_oj()
File "/tmp/pip-install-pm4x0cuw/pylibjpeg-openjpeg_aa94277196914aa0977c3af9a91bdadd/setup.py", line 60, in setup_oj
shutil.copy(
File "/usr/lib/python3.10/shutil.py", line 417, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.10/shutil.py", line 254, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'build_tools/cmake/CMakeLists.txt'
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/49/1c/43de9deec30e2a641a3a2f11efa6c13185fa2c77a962676e370a282a3814/pylibjpeg-openjpeg-1.1.0.tar.gz#sha256=66514f5d5df6fdfc704296a8420e4b1feb335fad4e6901435e00c37f353fb44e (from https://pypi.org/simple/pylibjpeg-openjpeg/) (requires-python:>=3.7). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Collecting pylibjpeg
Using cached pylibjpeg-1.2.0-py3-none-any.whl (27 kB)
Using cached pylibjpeg-1.1.1-py3-none-any.whl (29 kB)
Using cached pylibjpeg-1.1.0-py3-none-any.whl (29 kB)
Using cached pylibjpeg-1.0.0-py2.py3-none-any.whl (31 kB)
Requirement already satisfied: numpy in /usr/lib/python3.10/site-packages (from pylibjpeg) (1.21.5)
Installing collected packages: pylibjpeg
Successfully installed pylibjpeg-1.0.0
Anything I can do to fix this?
Managed to get it to work after uninstall, clone, install development version, install pylibjpeg-libjpeg:
pip uninstall --user pylibjpeg
git clone git@github.com:pydicom/pylibjpeg.git
pip install --user ./pylibjpeg
pip install --user pylibjpeg-libjpeg
Output is now
> python -m pydicom.env_info
module | version
------ | -------
platform | Linux-5.15.12-arch1-1-x86_64-with-glibc2.33
Python | 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0]
pydicom | 2.2.2
gdcm | _module not found_
jpeg_ls | _module not found_
numpy | 1.22.0
PIL | 8.4.0
pylibjpeg | 1.4.0
openjpeg | _module not found_
libjpeg | 1.2.0
Thank you, that works!
This was failing to build -openjpeg with Python 3.10 due to a file that was missing from the -openjpeg package. It should be fixed now anyway.