Search code examples
pythonpython-importmodulenotfounderror

Package only imports when I run python3


I just installed a package and the first step to testing (found here) tells me to cd into a "tests" directory and run nosetests. Nosetests gives me a ModuleNotFoundError:

ERROR: Failure: ModuleNotFoundError (No module named 'clawpack')

which is prompted when each of the tests import clawpack (the package).

What I have figured out so far:

If I run "python" in my home directory, I can use the command "import clawpack" without error. However, when I am in the tests directory, "import clawpack" only works if I run "python3" and not "python." If I am running "python," "import clawpack" gives me the same ModuleNotFoundError above.

Any suggestions for how to rectify this issue would be much appreciated.


Solution

  • You might have multiple Python versions installed, and packages installed with one version won't be available to the other. You can test which Python version you are using with which python and which python3.

    How are you installing clawpack with pip? To ensure you are using the pip utility that corresponds to the correct Python binary, you can run python3 -m pip install clawpack.

    Also, if you have a folder for clawpack in your home directory, then the folder in your current directory is what is imported.