Import cobra

156 views
Skip to first unread message

Alejandro Cano

unread,
Jan 12, 2022, 8:05:27 AM1/12/22
to cobra pie
Hi everyone,

I'm a new user of CobraPy that used to work with Cobra toolbox in Matlab. I followed all the steps to install CobraPy in a Conda enviroment but when I run the "import cobra" line I get the following message.

Traceback (most recent call last):
  File "C:\Conda\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-e8543d93f282>", line 1, in <module>
    import cobra
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Conda\lib\site-packages\cobra\__init__.py", line 17, in <module>
    from cobra import io
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Conda\lib\site-packages\cobra\io\__init__.py", line 9, in <module>
    from cobra.io.web import AbstractModelRepository, BiGGModels, BioModels, load_model
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Conda\lib\site-packages\cobra\io\web\__init__.py", line 6, in <module>
    from .biomodels_repository import BioModels
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Conda\lib\site-packages\cobra\io\web\biomodels_repository.py", line 14, in <module>
    class BioModelsFile(pydantic.BaseModel):
  File "C:\Conda\lib\site-packages\cobra\io\web\biomodels_repository.py", line 18, in BioModelsFile
    size: int = pydantic.Field(alias="fileSize")
AttributeError: module 'pydantic' has no attribute 'Field'

Hope some of you can help me with this issue. Thank you.

Dennis van den Berg

unread,
Jan 12, 2022, 8:15:39 AM1/12/22
to Alejandro Cano, cobra pie
Hi Alejandro,

Can you try to import cobrapy in a jupyter notebook instead of JetBrains? Just to see if it is not a problem with the IDE.

Kind regards,

Dennis

--
You received this message because you are subscribed to the Google Groups "cobra pie" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cobra-pie+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cobra-pie/5be58eeb-b138-4180-813b-7a1f2a4a2e2an%40googlegroups.com.

Alejandro Cano

unread,
Jan 12, 2022, 8:30:11 AM1/12/22
to cobra pie
Screenshot 2022-01-12 at 08-28-20 Untitled - Jupyter Notebook.png

Dennis van den Berg

unread,
Jan 12, 2022, 9:20:52 AM1/12/22
to Alejandro Cano, cobra pie
Hi Alejandro,

Do you happen to be running python 3.10?
And is your version of pydantic 1.9.0? Older versions are incompatible with python 3.10.

Regards,

Dennis

Alejandro Cano

unread,
Jan 12, 2022, 9:29:44 AM1/12/22
to cobra pie
Currently I'm running python 3.8.8 and the version of pydantic that I have is 0.18.2.

Should I update both of them?

Regards,

Alejandro.

Dennis van den Berg

unread,
Jan 12, 2022, 10:06:17 AM1/12/22
to Alejandro Cano, cobra pie
That version of pydantic is really low. My environment with python 3.8.12 is running pydantic 1.8.2 and cobra 0.22.1
That runs fine, so can you check in your ' conda list' command if pydantic is not from the pip channel. If so you can update it using ' conda install -c conda-forge pydantic'

Hope this helps,

Dennis

Dennis van den Berg

unread,
Jan 12, 2022, 10:07:16 AM1/12/22
to Alejandro Cano, cobra pie
My bad, I meant channel Pypi not pip.

ch.d...@gmail.com

unread,
Jan 12, 2022, 5:13:18 PM1/12/22
to cobra pie
Ye, as others said the pydantic version is too low. The smallest supported version is 1.6. There is a missing version requirement in the conda package. I'll add it there to avoid this in the furure.
Reply all
Reply to author
Forward
0 new messages