I just install PyFoam using:
pip install PyFoam
Then I wrote a test.py file using:
import PyFoam
Now I got an error message:
import PyFoam
ImportError: No module named PyFoam
Then I tried install again, and I got this:
pip install PyFoam
Requirement already satisfied: PyFoam in ./.local/lib/python3.8/site-packages (2021.6)
Requirement already satisfied: numpy in ./.local/lib/python3.8/site-packages (from PyFoam) (1.23.0)
Could anyone help? Tks.
The issue is likely that you use one version of pip and another version of the Python interpreter. This is particularly common if you have several Python installations on your system. Check that these versions match with each other.
For example, run
You should see output similar to the following:
Notice the matching version numbers. I am verifying this on my system with Homebrew, under MacOS, but I assume that it's similar on other systems. Here, different instances of "python" and "pip" binaries are suffixed with the version number. So, if your version of "pip" says "3.8", try specifying "python3.8" as interpreter.
It might also be helpful for troubleshooting to know of the "-m" switch, in order to locate a module. In your example, you would run:
Notice the capitalization for this module, which can differ between the one being used to install the module through pip and when importing it. On my system, as an example, it outputs:
The error message is fine. It does still mean the module was found. That is in contrast to an output like the following:
The -m switch is documented under https://peps.python.org/pep-0338/.
Another possibility might be that you need to check and configure your Python module search path, as described here https://docs.python.org/3/tutorial/modules.html.
It's possible to try to think of other causes. But without any additional information about your setup it would probably be too speculative and become confusing for other people reading this answer, so I will leave it at these two causes, which I believe to be the most common for this type of issue.