opencobra / cobrapy

COBRApy is a package for constraint-based modeling of metabolic networks.
http://opencobra.github.io/cobrapy/
GNU General Public License v2.0
455 stars 211 forks source link

Cannot import cobra: import error involving numpy #1339

Closed CNelias closed 1 year ago

CNelias commented 1 year ago

Problem description

When trying to do import cobra i get the following error:

ImportError: cannot import name 'object' from 'numpy' (C:\Users\Corentin offline\AppData\Roaming\Python\Python310\site-packages\numpy\__init__.py)

The full stack trace goes:

C:\ProgramData\anaconda3\lib\site-packages\cobra\io\mat.py:13: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
  from numpy import object as np_object
Traceback (most recent call last):

  Cell In[4], line 1
    import cobra

  File C:\ProgramData\anaconda3\lib\site-packages\cobra\__init__.py:17
    from cobra import io

  File C:\ProgramData\anaconda3\lib\site-packages\cobra\io\__init__.py:6
    from cobra.io.mat import load_matlab_model, save_matlab_model

  File C:\ProgramData\anaconda3\lib\site-packages\cobra\io\mat.py:13
    from numpy import object as np_object

I am running on windows 11, with python 3.10.

cdiener commented 1 year ago

Looks like we missed a deprecation for the numpy type aliases. I will send in a fix. For now downgrading numpy to 1.24.x should work.

CNelias commented 1 year ago

Still does not work after downgrading

cdiener commented 1 year ago

That is weird because our CI runs with numpy=1.24.3 on Windows as well and all looks good there... Can you fill out the rest of the issue template, specifically the output of python -c "import cobra; cobra.show_versions()"?

Thanks!

cdiener commented 1 year ago

Diving a bit deeper, it looks like this was already fixed in #1153 last year. So updating cobrapy to the latest version (0.26.3) should fix this.