How to install cantera in google colab

404 views
Skip to first unread message

raju darshan

unread,
Dec 2, 2020, 4:38:57 PM12/2/20
to Cantera Users' Group
Hi users,

Does anyone knew how to install cantera in google colab. I installed conda into colab and then cantera.
################################################################################
# INSTALL CONDA ON GOOGLE COLAB
################################################################################
! bash ./Anaconda3-py37_4.8.2-Linux-x86_64.sh -b -f -p /usr/local
!conda install --channel cantera/label/dev cantera
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')

when I see my conda list in colab I can see cantera in it but I can't able to import cantera from conda

!conda list

when I tried to import cantera it show me this error

raju darshan

unread,
Dec 2, 2020, 4:47:56 PM12/2/20
to Cantera Users' Group
conda list.png
error.png

Bryan W. Weber

unread,
Dec 3, 2020, 9:14:13 AM12/3/20
to Cantera Users' Group
Hi,

On this line:

sys.path.append('/usr/local/lib/python3.7/site-packages/')

I don't think that Miniconda installs itself to /usr/local/lib... if you specify the -p option to the installer, I would expect it go to into /usr/local/miniconda3/... But I've not done this before, so I could be wrong. Try listing out the filesystem paths in the /usr/local folder and see which folders exist.

Best,
Bryan

raju darshan

unread,
Dec 3, 2020, 8:30:52 PM12/3/20
to Cantera Users' Group
Hi Brian,

I tried to list out the file system path and came to know cantera location /usr/local/lib/python3.8/site-packages/cantera  In that folder I have all the data files but still I can't able to import it

Kind Regards,
Raju

Bryan W. Weber

unread,
Dec 10, 2020, 10:14:34 PM12/10/20
to Cantera Users' Group
It seems likely that there is a difference between the version of Python running on colab and the version of Python that Cantera was installed for. What is the output of

!python -V

I'm confused how the Cantera files ended up in the Python 3.8 site-packages directory since you installed Anaconda with Python 3.7...

Best,
Bryan

raju darshan

unread,
Dec 12, 2020, 7:47:51 PM12/12/20
to canter...@googlegroups.com
Hi Brian,

I managed to install python 3.7 in colab and I can see cantera is in python3.7/site-packages. But still I can't able to import. I have attached the screenshot of the error I am getting while I am trying to import cantera.

Kind regards
Darshan

--
You received this message because you are subscribed to a topic in the Google Groups "Cantera Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cantera-users/57xH6wu4pwg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/990b8376-e2c4-4eaf-899d-bfbab9bd8035n%40googlegroups.com.
colab_error.png

Bryan W. Weber

unread,
Dec 12, 2020, 9:45:06 PM12/12/20
to Cantera Users' Group
Hi Darshan,

Unfortunately, I've never used Colab before, so I'm not sure how to continue debugging this. Does the expected _cantera file exist somewhere in that directory? Do all the versions/file names match with the appropriate architecture/Python version? Do you have to continue using Colab, or can you install Anaconda on your own computer?

On a separate note, can you please copy/paste the error messages and code into your post, rather than a screenshot? There are a few reasons to prefer copy/pasting text directly, including searchability (text is searchable, images are not) and readability (text can be read by screen readers for blind users, images cannot). Thank you!

Best,
Bryan

raju darshan

unread,
Dec 12, 2020, 10:59:09 PM12/12/20
to canter...@googlegroups.com
Hi Brian, 

Finally I found a way to import cantera into google colab from [https://towardsdatascience.com/conda-google-colab-75f7c867a522]. Initially, the PYTHONPATH variable should be unset before installing Miniconda as it can cause problems if there are packages installed and accessible via directories included in the PYTHONPATH that are not compatible with the version of Python included with Miniconda. And then I Installed Miniconda and updated.  I have uploaded the colab file which contains the commands to import Cantera into Colab.


Kind regards
Darshan

You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/68cfe122-13fd-4a21-b445-5e881e5116a8n%40googlegroups.com.
CANTERA.ipynb

Bryan W. Weber

unread,
Dec 14, 2020, 3:15:44 PM12/14/20
to Cantera Users' Group
Great, I'm glad you got it working! Thank you for posting those steps.

Bryan

Leonardo Baptista

unread,
Jan 5, 2021, 9:30:47 AM1/5/21
to Cantera Users' Group
Hi,

I'm using cantera in google colab almost an year using the following lines:

!apt-add-repository ppa:speth/cantera
!apt-get -qq install -y cantera-python cantera-python3 cantera-dev

Those lines will install the cantera in the notebook.Further, it will be necessary to upload your .cti file using the lateral bar of Google Colab.
After the installation, will can edit your python scritp to run cantera as you wish.

Remember that the install and upload procedure should be done every time if you use a Colab free account.


Reply all
Reply to author
Forward
0 new messages