ImportError: cannot import name 'bioformats' from 'pims' (unknown location)
ctpn opened this issue · 4 comments
Hello,
Following conda install -c conda-forge pims
and conda install jpype1 -c conda-forge
, I can import pims
(Python 3.8), but the module is empty. i.e. none of the functions show up in the Variables list (e.g. bioformats, image_reader) even though the .py files are in the pims folder on my computer.
Error:
import pims
from pims import bioformats
Traceback (most recent call last):
File "/home/charissa/.local/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-7-e3b2fb39d32c>", line 1, in <module>
from pims import bioformats
ImportError: cannot import name 'bioformats' from 'pims' (unknown location)
Dependencies show up in conda list
:
pims 0.5 pyh9f0ad1d_1 conda-forge
numpy 1.20.1 pypi_0 pypi
slicerator 1.0.0 py_0 conda-forge
scikit-image 0.17.2 py38hdf5156a_0
matplotlib 3.3.4 py38h06a4308_0
pillow 6.1.0 pypi_0 pypi
jinja2 2.11.3 pyh44b312d_0 conda-forge
python 3.8.8 hdb3f193_4
Any advice would be appreciated, thanks very much for your time.
I figured it out.
Re Petr Zemek's post, the pims module was for some reason (any insight here would be appreciated!) imported as a namespace package instead of a regular package. The error appears to actually be a PermissionError. I seem to have full permissions to the pims directory. However, print(sys.path)
revealed that the directory containing the pims folder was actually not part of the search path for modules. This was solved by sys.path.insert(0, [path to pims folder])
, followed by import pims
etc.
Encountered the same issue after restarting the computer. Any advice would be appreciated, thank you.
Hmm… I'm hardly an expert on this, but it looks like your Jupyter package in .local
was not installed by conda. (Maybe via pip
instead? Or am I just really rusty on how conda works now?) That's not a problem by itself, but it makes me wonder if you need to run something like conda activate
so that you are at least running Python in the same environment in which you installed pims
.
Thanks for your reply! You are right. A bit embarrassing but turns out that I had conda install pims
to my virtual environment, but my Python interpreter was local. Switching the interpreter to the conda virtual environment solved it.
In case anyone else has this issue: https://stackoverflow.com/questions/36539623/how-do-i-find-the-name-of-the-conda-environment-in-which-my-code-is-running