3

I ran the command pip install coverage and it appears to have installed correctly.

Frodo:Triangle567 tarikkdiry$ pip install coverage
    Collecting coverage
      Using cached https://files.pythonhosted.org/packages/c7/d0/337673c08f5b0cc7ada3dfe2a998ae8a97d482722045644be3d79bbcbe05/coverage-4.5.1-cp37-cp37m-macosx_10_13_x86_64.whl
    Installing collected packages: coverage
    Successfully installed coverage-4.5.1

However, after running coverage on one of my test files, I receive this error:

Frodo:Triangle567 tarikkdiry$ coverage run testtriangle.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/coverage", line 7, in <module>
    from coverage.cmdline import main
ModuleNotFoundError: No module named 'coverage.cmdline'; 'coverage' is not a package
Frodo:Triangle567 tarikkdiry$

I have tried uninstalling every python package and reinstalling but to no success. I have tried this on another machine and can confirm the test file is working properly.

EDIT: After running pip3 check coverage and pip3 show coverage

pip3 check coverage:

No broken requirements found.

pip3 show coverage

Name: coverage
Version: 4.5.1
Summary: Code coverage measurement for Python
Home-page: https://bitbucket.org/ned/coveragepy
Author: Ned Batchelder and 100 others
Author-email: [email protected]
License: Apache 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
Requires:
Required-by:
4
  • 1
    Edit your Question and show your Python Version and the output of pip3 check coverage and pip3 show coveragel. Commented Sep 30, 2018 at 17:10
  • Relevant: python-custom-module-not-found-but-already-exists Commented Sep 30, 2018 at 17:18
  • Do you have a file named coverage.py in your current directory? Commented Sep 30, 2018 at 21:27
  • @jwodder yes I do Commented Sep 30, 2018 at 21:31

4 Answers 4

4

You should check if coverage refer to python or python3. Most likely it uses python to run exact tool you need. Default python version on macOS is python 2.7.

Another option is to create a virtual environment by running python3.7 -m venv $directory (where $directory contains a folder for virtual environment, you can use direct paths as you wish), then activating it by running source $directory/bin/activate. After doing this, you'll have no problems finding all packages you want. I personally prefer this method over installing packages into the system.

Additionally, you can install python3.7 from MacPorts or Homebrew and activate it as a default python. For many libraries you can install them using these package managers as well.

Sign up to request clarification or add additional context in comments.

Comments

4

What worked for me:

python -m coverage run arg1 arg2 arg3

Instead of what is mentioned on https://coverage.readthedocs.io/en/6.0.2/

coverage run arg1 arg2 arg3

Which is similar to this answer for Windows: https://stackoverflow.com/a/36656924/264359

Comments

2

I encountered this on Windows when running pip install coverage when using the mingw64 (bash for Windows) shell. Pip detected a linux environment and didn't include the .exe that Windows needs.

To resolve this I ran pip uninstall coverage then opened an administrative PowerShell prompt and ran pip install coverage.

Comments

1

According to the comments, you have a file named coverage.py in your current working directory. This file is interfering with the coverage command's attempts to import from coverage.cmdline. You need to rename the file to something else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.