cobaya: cannot open cobaya-cosmo-generator

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Jiwon Park
Posts: 9
Joined: July 09 2019
Affiliation: Soongsil University

cobaya: cannot open cobaya-cosmo-generator

Post by Jiwon Park » June 03 2021

Dear all,

I'm trying to use a GUI input generator in cobaya with the command 'cobaya-cosmo-generator,' but it keeps giving this error.

Code: Select all

Traceback (most recent call last):
  File "/home/cosmos/.local/bin/cobaya-cosmo-generator", line 7, in <module>
    from cobaya.cosmo_input import gui_script
ImportError: cannot import name 'gui_script'
I use Linux Mint 19.3 and the most recent version of cobaya and have installed pyqt5 and pyside2 with pip3 recently.
I don't think the problem depends on some particular type of system, as I've already tried the same command on the ubuntu wsl system.
It gives a similar error like this:

Code: Select all

Traceback (most recent call last):
  File "/home/cosmos/.local/bin/cobaya-cosmo-generator", line 7, in <module>
    from cobaya.cosmo_input import gui_script
ImportError: cannot import name 'gui_script' from 'cobaya.cosmo_input' (/home/cosmos/.local/lib/python3.8/site-packages/cobaya/cosmo_input/__init__.py)
How can I resolve this problem?

Antony Lewis
Posts: 1936
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: cobaya: cannot open cobaya-cosmo-generator

Post by Antony Lewis » June 04 2021

Try installing cobaya and running in a clean conda environment, e.g.

conda create -n py39forge -c conda-forge python=3.9 scipy pandas matplotlib PyYAML PySide2

The pip installation of pyside2 seems to be very unreliable.

Jiwon Park
Posts: 9
Joined: July 09 2019
Affiliation: Soongsil University

Re: cobaya: cannot open cobaya-cosmo-generator

Post by Jiwon Park » June 04 2021

Unfortunately, that didn't resolve the problem.

I used the following commands to install cobaya:

Code: Select all

conda create -n py39forge -c conda-forge python=3.9 scipy pandas matplotlib PyYAML PySide2

conda activate py39forge

python -m pip install cobaya[gui] --upgrade
The installation was successful. But when I run 'cobaya-cosmo-generator,' the same error arose:

Code: Select all

Traceback (most recent call last):
  File "/home/cosmos/anaconda3/envs/py39forge/bin/cobaya-cosmo-generator", line 5, in <module>
    from cobaya.cosmo_input import gui_script
ImportError: cannot import name 'gui_script' from 'cobaya.cosmo_input' (/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/cobaya/cosmo_input/__init__.py)
I guessed that there might be a problem when installing cobaya with pip because pip reinstalls pyside2 with a different version, as conda installs version 5.13.2:

Code: Select all

  pyside2            conda-forge/linux-64::pyside2-5.13.2-py39h363ec45_4
whereas pip installs a different version(5.15.2):

Code: Select all

Collecting pyside2
  Using cached PySide2-5.15.2-5.15.2-cp35.cp36.cp37.cp38.cp39-abi3-manylinux1_x86_64.whl (164.3 MB)
So I manually reinstalled everything with a new environment, with these commands:

Code: Select all

conda create -n py39forge2 -c conda-forge python=3.9 scipy pandas matplotlib PyYAML PySide2

conda activate py39forge2

pip install -r requirements.txt --no-deps
where 'requirements.txt' is:

Code: Select all

GetDist==1.2.3
chardet==4.0.0
cobaya==3.0.4
shiboken2==5.13.2
fuzzywuzzy==0.18.0
idna==2.10
packaging==20.9
py-bobyqa==1.3
requests==2.25.1
urllib3==1.26.5
Note that I changed the version of shiboken2(5.15.2=>5.13.2), to fit with the pyside2 version installed by conda.

But it gives the same result.

Antony Lewis
Posts: 1936
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: cobaya: cannot open cobaya-cosmo-generator

Post by Antony Lewis » June 05 2021

Please can you try
1. cobaya 3.1 (released today)
2. see if "from PySide2.QtWidgets import QWidget" works from python running on py39forge
3. Add "raise" to the "except" in cosmo_input/__init__.py to see which explicit error there
4. Edit "except ImportError" in gui.py to print the actual error to see what the problem is in detail.
5. see if "getdist-gui" works

You do want 5.13 I think (at least that's what works for me)

Jiwon Park
Posts: 9
Joined: July 09 2019
Affiliation: Soongsil University

Re: cobaya: cannot open cobaya-cosmo-generator

Post by Jiwon Park » June 07 2021

I guess the problem is fixed now.

If I install cobaya(the new version you upgraded) with this command

Code: Select all

conda create -n py39forge -c conda-forge python=3.9 scipy pandas matplotlib PyYAML PySide2

conda activate py39forge

python -m pip install cobaya[gui] --upgrade
and try to run "cobaya-cosmo-generator," the following error arises:

Code: Select all

PySide2/__init__.py: Unable to import shiboken2 from /home/cosmos/anaconda3/envs/py39forge/bin, /home/cosmos/anaconda3/envs/py39forge/lib/python39.zip, /home/cosmos/anaconda3/envs/py39forge/lib/python3.9, /home/cosmos/anaconda3/envs/py39forge/lib/python3.9/lib-dynload, /home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages
Traceback (most recent call last):
  File "/home/cosmos/anaconda3/envs/py39forge/bin/cobaya-cosmo-generator", line 5, in <module>
    from cobaya.cosmo_input import gui_script
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/cobaya/cosmo_input/__init__.py", line 2, in <module>
    from .gui import gui_script
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/cobaya/cosmo_input/gui.py", line 33, in <module>
    from PySide2.QtWidgets import QWidget, QApplication, QVBoxLayout, QHBoxLayout, \
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/PySide2/__init__.py", line 107, in <module>
    _setupQtDirectories()
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/PySide2/__init__.py", line 58, in _setupQtDirectories
    import shiboken2
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/shiboken2/__init__.py", line 30, in <module>
    _init_pyside_extension()
NameError: name '_init_pyside_extension' is not defined
and I became sure that the problem occurs due to pyside2 and shiboken2 installed by pip because there was no problem with running this command

Code: Select all

from PySide2.QtWidgets import QWidget
before installing cobaya with pip, whereas after installing cobaya, python shows the following same error:

Code: Select all

>>> from PySide2.QtWidgets import QWidget
PySide2/__init__.py: Unable to import shiboken2 from , /home/cosmos/anaconda3/envs/py39forge/lib/python39.zip, /home/cosmos/anaconda3/envs/py39forge/lib/python3.9, /home/cosmos/anaconda3/envs/py39forge/lib/python3.9/lib-dynload, /home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/PySide2/__init__.py", line 107, in <module>
    _setupQtDirectories()
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/PySide2/__init__.py", line 58, in _setupQtDirectories
    import shiboken2
  File "/home/cosmos/anaconda3/envs/py39forge/lib/python3.9/site-packages/shiboken2/__init__.py", line 30, in <module>
    _init_pyside_extension()
NameError: name '_init_pyside_extension' is not defined
So I manually uninstalled and reinstalled two packages with version 5.13.2. Then everything runs fine.

I don't know if this kind of error is a general one, but it would be some help to note explicitly not to use version 5.15.2 version of pyside2(that is, installed by pip) in the document of cobaya?
Anyway, thank you for helping me, Lewis!

Antony Lewis
Posts: 1936
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: cobaya: cannot open cobaya-cosmo-generator

Post by Antony Lewis » June 07 2021

Thanks, I've updated the docs to remove the "[gui]" which seems to be causing the confusion here.

Post Reply