mamba icon indicating copy to clipboard operation
mamba copied to clipboard

AttributeError: module 'libmambapy' has no attribute 'QueryFormat'

Open zertrin opened this issue 3 years ago • 18 comments

I just installed mamba in an existing miniconda base environment (created a while ago) and tried to use it to create a new environment, but I get the following error. Some googling didn't turn up previous reports so far.

I'm on Windows 10 (21H1 build 19043.1415).

Tried with mamba 0.19.1 (the one that got installed after conda install mamba -c conda-forge), then tried downgrading to 0.18.1 since that one is the last release according to the GitHub project.

(base) PS D:\Zertrin\xxxx\xxxx\xxxx\xxxx> mamba env create -n mambatest
Traceback (most recent call last):
  File "C:\Users\Zertrin\Miniconda3\Scripts\mamba-script.py", line 6, in <module>
    from mamba.mamba import main
  File "C:\Users\Zertrin\Miniconda3\lib\site-packages\mamba\mamba.py", line 50, in <module>
    from mamba import repoquery as repoquery_api
  File "C:\Users\Zertrin\Miniconda3\lib\site-packages\mamba\repoquery.py", line 12, in <module>
    def _repoquery(query_type, q, pool, fmt=api.QueryFormat.JSON):
AttributeError: module 'libmambapy' has no attribute 'QueryFormat'

Here is the content of the base environment so far:

(base) PS D:\Zertrin\xxxx\xxxx\xxxx\xxxx> conda list
# packages in environment at C:\Users\Zertrin\Miniconda3:
#
# Name                    Version                   Build  Channel
brotlipy                  0.7.0           py37hcc03f2d_1003    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2021.10.8            h5b45459_0    conda-forge
certifi                   2021.10.8        py37h03978a9_1    conda-forge
cffi                      1.15.0           py37hd8e9650_0    conda-forge
charset-normalizer        2.0.9              pyhd8ed1ab_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
conda                     4.11.0           py37h03978a9_0    conda-forge
conda-package-handling    1.7.3            py37ha54c9ec_1    conda-forge
console_shortcut          0.1.1                         3
cryptography              36.0.1           py37h65266a2_0    conda-forge
flake8                    3.6.0                    py37_0
idna                      3.1                pyhd3deb0d_0    conda-forge
krb5                      1.19.2               h20d022d_3    conda-forge
libarchive                3.5.2                hb45042f_1    conda-forge
libcurl                   7.80.0               h789b8ee_1    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
libmamba                  0.19.1               h44daa3b_0    conda-forge
libmambapy                0.19.1           py37ha07342c_0    conda-forge
libsolv                   0.7.19               h7755175_5    conda-forge
libssh2                   1.10.0               h680486a_2    conda-forge
libxml2                   2.9.12               hf5bbc77_1    conda-forge
libzlib                   1.2.11            h8ffe710_1013    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
lzo                       2.10              he774522_1000    conda-forge
mamba                     0.19.1           py37h13f6ddf_0    conda-forge
mccabe                    0.6.1                      py_1    conda-forge
menuinst                  1.4.18           py37h03978a9_1    conda-forge
openssl                   1.1.1l               h8ffe710_0    conda-forge
pip                       21.3.1             pyhd8ed1ab_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycodestyle               2.4.0                    py37_0
pycosat                   0.6.3           py37hcc03f2d_1009    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyflakes                  2.0.0                    py37_0
pyopenssl                 21.0.0             pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1            py37h03978a9_4    conda-forge
python                    3.7.1             h9460c21_1003    conda-forge
python_abi                3.7                     2_cp37m    conda-forge
pywin32                   303              py37hcc03f2d_0    conda-forge
reproc                    14.2.3               h8ffe710_0    conda-forge
reproc-cpp                14.2.3               h0e60522_0    conda-forge
requests                  2.26.0             pyhd8ed1ab_1    conda-forge
ruamel_yaml               0.15.80         py37hcc03f2d_1006    conda-forge
setuptools                60.2.0           py37h03978a9_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
tk                        8.6.11               h8ffe710_1    conda-forge
tqdm                      4.62.3             pyhd8ed1ab_0    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
urllib3                   1.26.7             pyhd8ed1ab_0    conda-forge
vc                        14.2                 hb210afc_5    conda-forge
vs2015_runtime            14.29.30037          h902a5da_5    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0            py37h03978a9_3    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
yaml                      0.2.5                h8ffe710_2    conda-forge
yaml-cpp                  0.6.3                ha925a31_4    conda-forge
zlib                      1.2.11            h8ffe710_1013    conda-forge
zstd                      1.5.1                h6255e5f_0    conda-forge

Any idea?

zertrin avatar Jan 05 '22 20:01 zertrin

I guess no access to specific mamba libraries. I have this error if run ...\Scripts\mamba.exe from an usual cmd prompt. And no errors if run ...\condabin\mamba.bat

Official command promt for mambaforge has several entries for "mamba" in PATH:

(base) C:\Users\...>where mamba
C:\a\python\Library\bin\mamba.bat
C:\a\python\Scripts\mamba.exe
C:\a\python\condabin\mamba.bat

The first entry runs:

@CALL "%~dp0..\..\condabin\mamba.bat" %*

In "...\condabin\mamba.bat" there is expansion of PATH: (Try to search the libraries there...)

@SET PATH=!_sysp!;!_sysp!\Library\mingw-w64\bin;!_sysp!\Library\usr\bin;!_sysp!\Library\bin;!_sysp!\Scripts;!_sysp!\bin;%PATH%

sherdim avatar Jan 21 '22 11:01 sherdim

I'm also seeing this, investigating today.

jonashaag avatar Feb 10 '22 08:02 jonashaag

Can confirm that this is due to the shared object file not being found (on Windows, the .pyd file)

jonashaag avatar Feb 10 '22 16:02 jonashaag

What would the environment variable that's set incorrectly in that case?

jonashaag avatar Feb 10 '22 16:02 jonashaag

it sounds a lot like the PATH variable isn't properly set. Is this happening in powershell or cmd.exe?

wolfv avatar Feb 10 '22 17:02 wolfv

It doesn't seem to have anything to do with PATH because this works:

set PATH=X
set LIB=X
C:\Users\j\mambaforge\condabin\mamba

jonashaag avatar Feb 10 '22 17:02 jonashaag

OK, one thing that is really odd is that the libmambapy package contains multiple cp3XX-...pyd files. We're not cleaning up properly between the different outputs in our conda meta.yaml.

However, I don't know if this is related to this failure here. What python version are you using?

wolfv avatar Feb 10 '22 17:02 wolfv

I'm still not entirely sure what's going on here, this is from a CI pipeline with limited debugability. Python version in environment.yml is 3.8.

$ python --version
Python 3.7.9

$ C:\Miniconda\condabin\mamba.bat info (also: C:\Miniconda\Library\bin\mamba.bat)
...
python version : 3.9.5.final.0
...

$ C:\Miniconda\Scripts\mamba.exe info
...
AttributeError: module 'libmambapy' has no attribute 'QueryFormat'
...

Does it mean that for some reason, Pythonn 3.7 is used to execute mamba.exe whereas mamba.bat uses the correct version of the interpreter (3.9)?

jonashaag avatar Feb 10 '22 20:02 jonashaag

Yeah that's exactly the problem when you use the mamba.exe directly -- then the %PATH% is not properly set up and the dlls are not found.

The mamba.bat file does add the necessary directories to the %PATH% to make it work

wolfv avatar Feb 10 '22 20:02 wolfv

I wonder why it's only a problem on Windows. Where can I find the mamba.exe source code?

jonashaag avatar Feb 11 '22 07:02 jonashaag

I had the same problem and miniconda reinstallation solved it. Not quite innovative and profound solution but it worked. Seems like some broken dependencies in existing base environment.

szymonos avatar Feb 14 '22 09:02 szymonos

Where can I find the mamba.exe source code?

ping @wolfv

jonashaag avatar Feb 15 '22 22:02 jonashaag

Hey, sorry @jonashaag for the slow response. I am quite sure the mamba.exe file is autogenerated by setuptools from the entrypoints: https://github.com/mamba-org/mamba/blob/99c3485dae05fd1b5f2d78f42e3151987f9cad7a/mamba/setup.py#L41

wolfv avatar Feb 16 '22 15:02 wolfv

Yeah that's exactly the problem when you use the mamba.exe directly -- then the %PATH% is not properly set up and the dlls are not found.

The mamba.bat file does add the necessary directories to the %PATH% to make it work

I am also facing the same problem on windows

mamba.bat --help
Traceback (most recent call last):
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\Scripts\mamba-script.py", line 6, in <module>
    from mamba.mamba import main
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\lib\site-packages\mamba\mamba.py", line 50, in <module>
    from mamba import repoquery as repoquery_api
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\lib\site-packages\mamba\repoquery.py", line 12, in <module>
    def _repoquery(query_type, q, pool, fmt=api.QueryFormat.JSON):
AttributeError: module 'libmambapy' has no attribute 'QueryFormat'
psh ❯ mamba.exe --help
Traceback (most recent call last):
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\Scripts\mamba-script.py", line 6, in <module>
    from mamba.mamba import main
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\lib\site-packages\mamba\mamba.py", line 50, in <module>
    from mamba import repoquery as repoquery_api
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\lib\site-packages\mamba\repoquery.py", line 12, in <module>
    def _repoquery(query_type, q, pool, fmt=api.QueryFormat.JSON):
AttributeError: module 'libmambapy' has no attribute 'QueryFormat'
psh ❯ mamba --help
Traceback (most recent call last):
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\Scripts\mamba-script.py", line 6, in <module>
    from mamba.mamba import main
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\lib\site-packages\mamba\mamba.py", line 50, in <module>
    from mamba import repoquery as repoquery_api
  File "C:\Users\mtrevisa\AppData\Local\Continuum\envy\lib\site-packages\mamba\repoquery.py", line 12, in <module>
    def _repoquery(query_type, q, pool, fmt=api.QueryFormat.JSON):
AttributeError: module 'libmambapy' has no attribute 'QueryFormat'

marcelotrevisani avatar Feb 18 '22 18:02 marcelotrevisani

I discussed with @marcelotrevisani and he installed mamba in an environment different from the base env -- that is often problematic.

I wonder if @jonashaag @zertrin @sherdim that is also the case for you?

wolfv avatar Feb 22 '22 13:02 wolfv

In my case I tried to install mamba in the base environnement.

In the end I think I worked around it by reinstalling a fresh micromamba, but that was unfortunate that installing it in the existing base env of miniconda failed.

zertrin avatar Feb 22 '22 14:02 zertrin

I had the same problem and miniconda reinstallation solved it. Not quite innovative and profound solution but it worked. Seems like some broken dependencies in existing base environment.

I've found what was causing the issue for me. Maybe someone will make use of it. So I was installing mamba from conda-forge channel using command: conda install -n base -c conda-forge mamba, but on the other hand, I had a script for updating conda environment using mamba update --all, but it was using the default channel and after that, mamba became corrupted with AttributeError: module 'libmambapy' has no attribute 'QueryFormat'. Changing update command to mamba update -c conda-forge -all fixed the issue.

szymonos avatar Mar 06 '22 22:03 szymonos

I had similar issues as well, but I managed to work around them. I had mamba installed in the base env, as recommended. When running mamba from the base env all was fine, but as soon as I activated another env it didn't work. The tell was that mamba.bat was working as intended, it was the plain mamba that didn't work. This was using git bash on Windows 10, which doesn't seem to resolve names properly... The fix was to just alias mamba to mamba.bat in my bash profile.

CarlAndersson avatar Apr 06 '22 07:04 CarlAndersson