0

I am trying to use Cantera on python. I downloaded Anaconda and followed the instructions on Cantera's website to install. Their website's tutorial says to write:

import cantera as ct
import numpy as np

When I run it, I get the error:

ModuleNotFoundError: No module named 'cantera'

I tried reinstalling everything.

Saritus
  • 918
  • 7
  • 15
MarkS
  • 1
  • 1
  • 1

4 Answers4

1

The error ModuleNotFoundError: No module named 'cantera' implies that you have not succesfully installed the 'cantera' module. You stated you downloaded anaconda then followed the install procedure here?

Can you please show me what the output was for this, if there was an error or admin block then cantera was never installed and that is why you can't import it.

Cavenfish
  • 366
  • 2
  • 13
  • After activating the environment in terminal, I entered conda install --channel cantera cantera Collecting package metadata (current_repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.7.10 latest version: 4.7.11 Please update conda by running $ conda update -n base -c defaults conda # All requested packages already installed. – MarkS Aug 21 '19 at 20:24
  • When I try this with a different base though, The response is different. – MarkS Aug 21 '19 at 20:33
  • 1
    Solving environment: failed with current_repodata.json, will retry with next repodata source. Initial quick solve with frozen env failed. Unfreezing env and trying again. Solving environment: failed with current_repodata.json, will retry with next repodata source. Collecting package metadata (repodata.json): done Solving environment: failed Initial quick solve with frozen env failed. Unfreezing env and trying again. Solving environment: failed UnsatisfiableError: The following specifications were found to be incompatible with each other: – MarkS Aug 21 '19 at 20:33
1

You might not be activating your environment. Activate it first in the command prompt and then try to import the modules.

  • 1
    It's good to be a bit more descriptive about your solution to the asked questions, like how they are gonna exactly solve it. – Nikhil Singh Jul 26 '20 at 05:33
0

Without knowing the complete detail, my guess is that when you start a new project with Pycharm, it offers to create a new environment for you (See the image below).

New Project Screenshot

An environment acts as an isolated container of packages and multiple environments can be setup (over simplification). By default, when creating a new environment it will only install the default packages with Anaconda and my guess is that Cantera is not a part of that list.

Now you've got two options:

  1. Specifically install the package in the new environment you created:

Click on File -> Settings -> Project -> Project Interpreter

Click the + button on the right hand side of the package list and then look for the package you want to install. It should be installed to your specified environment.

  1. Change the environment to the default anaconda env:

Click on File -> Settings -> Project -> Project Interpreter

In the Project Interpreter drop down, select the default anaconda interpreter. You can look at the packages installed in that env and find if your specific package is there or not. If the package is still not there, you could go ahead and install it using the previous method.

razdi
  • 1,388
  • 15
  • 21
  • Im on preferences for new projects... Do I select Python 3.7 as my interpreter? – MarkS Aug 21 '19 at 20:58
  • That would be my guess. Select that and a list of packages will populate below it. You can check if Cantera exists in that list. If not, you should be able to install it using the `+` button. – razdi Aug 21 '19 at 22:52
0

I have gone through a large amount of pain to eventually conclude that: Cantera 2.4 will work only with Python 2.7, and a new Python 2.7 environment within Anaconda can be used to install it, though I didn't find this written clearly:Cantera Release Notes

To install and run Cantera 2.4:

  1. Create and activate a Python 2.7 environment: Anaconda Documentation
  2. Run the command: conda install -c cantera cantera (first iteration may fail to solve) - Anaconda Documentation
  3. View your Python 2 environment packages in in Anaconda and you will see it listed.
Jane
  • 1