Coverage python library not found after installing
Solution 1
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.
Solution 2
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
Solution 3
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
.
Solution 4
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.
![Tarik Kdiry](https://i.stack.imgur.com/7cM1r.png?s=256&g=1)
Tarik Kdiry
Updated on June 05, 2022Comments
-
Tarik Kdiry about 2 years
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:
-
stovfl over 5 yearsEdit your Question and show your Python Version and the output of
pip3 check coverage
andpip3 show coveragel
. -
stovfl over 5 years
-
jwodder over 5 yearsDo you have a file named
coverage.py
in your current directory? -
Tarik Kdiry over 5 years@jwodder yes I do
-