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: ned#nedbatchelder.com
License: Apache 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
Requires:
Required-by:
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.
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
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.
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.
Related
On both MacOS 10.15.7 (Python 3.8.6) and Ubuntu 20.04 (Python 3.8.5), I have installed various virtual environments for various Python scripts I am writing (all in Git and on Github). The projects use pyproject.toml for use with flit. I created and populated the environments with modules used in the scripts as follows (where $VENVS is the directory where I keep virtual environments):
$ python3 -m venv $VENVS/csvenv
$ source $VENVS/csvenv/bin/activate
(csvenv) $ python3 -m pip install --upgrade flit
(csvenv) $ flit install -s # to install script as "editable"
HOWEVER, on both platforms the command python3 -m pip freeze gets different results, when executed in a virtual environment:
In environments created before August 17, it displays the installed modules (as it should).
In newer environments, I get:
ERROR: Exception:
Traceback (most recent call last):
File "/Users/tbaker/venvs/dcapenv/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 228, in _main
status = self.run(options, args)
File "/Users/tbaker/venvs/dcapenv/lib/python3.8/site-packages/pip/_internal/commands/freeze.py", line 101, in run
for line in freeze(**freeze_kwargs):
File "/Users/tbaker/venvs/dcapenv/lib/python3.8/site-packages/pip/_internal/operations/freeze.py", line 67, in freeze
req = FrozenRequirement.from_dist(dist)
File "/Users/tbaker/venvs/dcapenv/lib/python3.8/site-packages/pip/_internal/operations/freeze.py", line 257, in from_dist
req = direct_url_as_pep440_direct_reference(
File "/Users/tbaker/venvs/dcapenv/lib/python3.8/site-packages/pip/_internal/utils/direct_url_helpers.py", line 49, in direct_url_as_pep440_direct_reference
assert not direct_url.info.editable
AssertionError
My guess that this depends on when an environment was created is based both on directory timestamps and on examination of builds on Readthedocs, which rebuilds documentation whenever a repo is pushed.
Documentation for a project with an environment created before August 17 has continued to rebuild without interruption, while the documentation for a project with the newer environment has failed to build since August. With the August 17 commit, a requirements.txt file was added.
If I restore that requirements.txt, the RTD build fails with this message:
ERROR: Could not find a version that satisfies the requirement csv2shex==0.2 (from -r docs/requirements.txt (line 16)) (from versions: none)
ERROR: No matching distribution found for csv2shex==0.2 (from -r docs/requirements.txt (line 16))
If I exit the virtual environment with deactivate, execute python3 -m pip freeze >requirements.txt (which works outside of the virtual environment) and push, Readthedocs fails to build with the same error.
pip freeze >requirements.txt does work when I use a virtual environment created in July. However, when I clone that project on Ubuntu and re-create a virtual environment (as above), pip freeze raises the exception. It also fails if I create and populate a new virtual environment for that on MacOS. However, if I create a new requirements.txt file within the virtual environment from July, and push, the documentation builds.
The exception is raised at line 49 of pip's direct_url_helpers.py, which includes the following comment:
# pip should never reach this point for editables, since
# pip freeze inspects the editable project location to produce
# the requirement string
assert not direct_url.info.editable
I have researched this for many hours. Searches on pip freeze, AssertionError, editable project location, and the like have turned up nothing. The Stackoverflow search "pip freeze assertionerror" yields just 12 results, all but one from 2015, or before, plus one from 2019 about an issue involving Docker.
To summarize, it appears to me that:
On my MacOS and Ubuntu systems, pip freeze does not work in virtual environments created since August 17 (using python3 -m venv)
Readthedocs documentation builds succeed in the presence of a requirements.txt file built using a virtual environment older than August 17.
Readthedocs documentation builds fail in the presence of a requirements.txt file built outside of any virtual environment -- always with the message above, which refers to
However, some things do not add up:
I am fairly sure I would have created the requirements.txt file of August 17 from within the virtual environment because I never work with projects outside of the virtual environment. But how can that be unless pip freeze were working?
Can anyone out there explain? Is this a problem with python3 -m venv, flit, or something else? Am I at least correct to suspect that the failures of the RTD builds are somehow related to the failures of pip freeze?
The failure of pip freeze was indeed a bug in Pip 2.2. This bug has already been fixed for the upcoming Pip 2.3.
I upgraded python version from 3.7 to 3.8 using brew upgrade python3 however after upgrading pipenv and jupyter commands stopped working. These are the commands I've ran as of now other commands may not be working as well.
This is the output when I ran pipenv:
-bash: /usr/local/bin/pipenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
This is the output when I ran the jupyter command:
-bash: /usr/local/bin/jupyter: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
So I opened up the file /usr/local/bin/pipenv and the interpreter declared at the top is #!/usr/local/opt/python/bin/python3.7
So I changed it to #!/usr/local/opt/python/bin/python3.8 and ran pipenv command and this is the output:
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 5, in <module>
from pipenv import cli
ModuleNotFoundError: No module named 'pipenv'
I ran pip3 list command and this was the output
Package Version
---------- -------
pip 20.1.1
setuptools 49.2.0
wheel 0.34.2
So i went into /usr/local/lib and there were 2 folders named python3.7 and python3.8. The site-packages folder in python3.7 has all the modules I had previously installed but the site-packages folder in python3.8 contains only 3 modules which I got using pip3 list.
I don't fully understand the issue but I think all the older commands are still linked to python3.7 interpreter which no longer exists and secondly all the site packages need to be in /usr/local/lib/python3.8
Yes, site-packages are per-interpreter-version. (Also, virtualenvs tend to break when you upgrade your Python version.)
Just reinstall the packages you need with your new Python 3.8 based pip3.
I am trying to use venv for my project and it doesn't work correctly.
So first of all I am activating my venv and than use command "pip freeze" to check if there are no modules installed from my computer. And there is an output^
user#DESKTOP-JMJSO6O C:\Users\user\Desktop\app\Scripts
$ activate
(app) user#DESKTOP-JMJSO6O C:\Users\user\Desktop\app\Scripts
$ pip freeze
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
accessify==0.3.1
appdirs==1.4.3
attrs==19.3.0
backcall==0.1.0
beautifulsoup4==4.8.2
bleach==3.1.0
bs4==0.0.1
...
And that is incorrect because I have no modules installed in this venv. What could be the problem?
UPD:
Trying pip --version with venv:
(app) user#DESKTOP-JMJSO6O C:\Users\user\Desktop\app\Scripts $ pip --version
WARNING: pip is being invoked by an old script wrapper. This will fail in a future
version of pip. Please see github.com/pypa/pip/issues/5599 for advice on fixing the
underlying issue. To avoid this problem you can invoke Python with '-m pip' instead
of running pip directly. pip 20.0.2 from
C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\pip (python 3.8)
Also I have founded another problem. For example, I have two python files in one directory:
- app/
- main.py
- conf.py
And when I am trying to import conf as module in main.py, I got the error:
ModuleNotFoundError: No module named 'conf'
Maybe the problem is with Windows? Becuase on the laptop with Windows I don't have any problems like that.
It seems that this problem is caused by two versions of pip, or a fail update attempt.
I suggest that you try following these instructions.
Alternatively try running where pip and pip --version inside and out side the virtual-env and look for differences.
I hope you'll figure this out, the github thread suggests the problem still doesn't have an obvious solution.
I followed along with the package distribution tutorial for uploading a package on test.pypi.org from a Linux machine, and proceeded to try to install the package on a separate Windows machine.
On the Windows machine, I installed Python 3.8 and ticked the Add Python 3.8 to PATH box. No previous Python installation was present, and it installed to C:\Users\me\AppData\Local\Programs\Python\Python38\.
In Environmental Variables, my PATH under "Users variables" is: C:\Users\me\AppData\Local\Programs\Python38\Scripts\;C:\Users\me\AppData\Local\Programs\Python38\;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps.
My PATH under "System variables" is much longer, but it contains no Python directories.
I then downloaded and installed pip.
In Command Prompt, I first created a virtual environment with py -m venv tutorial and activated it with Scripts\activate. Activation was verified by the (tutorial) next to the prompt. Then, in the virtual env, with py -m pip install ... I installed my example package.
I can verify it's installed by seeing it in the output of py -m pip list:
Package Version
----------------------- -------
example-pkg-me 0.0.1
pip 19.2.3
setuptools 41.2.0
example-pkg-me does not appear outside the virtual env.
The tutorial finishes by having you attempt an import in the Python interpreter:
py
>>> import example_pkg
but I get ModuleNotFoundError: No module named `example_pkg`. Why? Is something wrong with either of my PATHs? Note that the tutorial specifically mentions omitting the username (and import example_pkg_me issues the same error regardless).
Curiously, when trying to install and import a "mainstream (?)" package, it succeeds with no errors. I.e.,
py -m pip install numpy
and
py
>>> import numpy
works.
Update:
Same results on a separate Linux machine with the same steps where the only differences are that Python and pip were already present.
As an aside, if your package is intended to be run (as a GUI app) rather than imported in the interpreter as in the tutorial, how would the person who installed it run it? Would they have to navigate to the directory where the package files were physically installed and run a main.py script there? Is there a better way (like freezing the package as an executable with the likes of cx_Freeze and distributing the EXE instead of relying on pip installations)? Or maybe just expect them to download a repository, run py setup.py install, and then a main.py script?
I installed Nose on a Mac OSX 10.10.5 with Python2.7.9 using easy_install. The installation appeared to be successful:
Collecting nose
Downloading nose-1.3.7-py2-none-any.whl (154kB)
100% |████████████████████████████████| 155kB 2.3MB/s
Installing collected packages: nose
Successfully installed nose-1.3.7
But now, when I try even basic stuff with nosetests on the command line, like nosetests -h or which nosetests I just get:
bash: nosetests: command not found
I have tried uninstalling, reinstalling using pip, tried installing with sudo and then running sudo nostests in the directories with tests scripts as other posts have suggested, but nothing seems to work.
The original purpose for installing was to use nose to run some basic tests with tests scripts I had written for these simple web.py apps. But nothing works, just keep getting the command not found response.
What's strange is that, when I open up the Python interpreter in Terminal, and do something like:
import nose
nose.main()
I get the expected result of:
.
----------------------------------------------------------------------
Ran 1 test in 0.135s
OK
So clearly it's installed....somewhere. Any suggestions for what the hell is going on here?
There are lots of error occurred when using pip install packages on Mac OS. So I recommend you install nose using easy_install.
$ pip uninstall nose
$ sudo easy_install nose
Then you can try nosetests now :)
I had this exact issue on OS X EI Captain with Python 2.7.10.
First I installed nose using pip:
$sudo pip install nose
which failed on the first attempt. Went through on the second attempt. But the nosetests command didn't work.
In order to fix this:
Step 1: Don't uninstall nose if it was installed already using pip as in my case.
Step 2:
$cd /usr/bin
$sudo easy_install nose
Above command finds the nosetests script (which was installed by pip earlier) & sets it under /usr/local/bin
Step 3: Try nosetests
$nosetests
----------------------------------------------------------------------
Ran 0 tests in 0.047s
OK
On UNIX-like systems like OS X, the script should be in /usr/local/bin. Make sure that directory is in the PATH environment variable in the shell that you use.
If not, you can also locate it using find, e.g:
find / -type f -name 'nosetests*' -perm +111 -print -quit
This means; search for a file whose name starts with nosetests, which has execute permissions set. Print the path name and stop.
I found that going to
Library/usr/bin
and running
sudo easy_install nose
it seems that sometimes it doesn't automatically install nose (and therefore nosetests functionality). Do the above lines, and you should be a-ok.
I wish i had a better explanation for why this happened, but i'm still pretty new, myself.
I had to use
Nosetest
or
python3 -m "nose"
Apparently this is the way Nosetest should be used in Python3. See also
How to make nosetests use python3
First, can you run 'python' from the command line? nosetests should be in that same directory:
rich bin $ which python
/home/rich/anaconda/bin/python
rich bin $ which nosetests
/home/rich/anaconda/bin/nosetests
It should also be in the downloaded nose package:
rich bin $ find /home/rich/anaconda -name nosetests
/home/rich/anaconda/pkgs/nose-1.3.3-py27_0/bin/nosetests
/home/rich/anaconda/pkgs/nose-1.3.7-py27_0/bin/nosetests
/home/rich/anaconda/bin/nosetests
From what I understand, everyone is moving to pytest - an actively-maintained testing framework.
It's not a solution to this problem, but it's likely the most-appropriate choice if you are still using nose.
I try to reinstall the pip, it doesn't work but lastly, when i use sudo ...it works
pip3 uninstall nose
sudo pip3 install nose
and
which nosetests
/usr/local/bin/nosetests
This can also happen if you were running nose within a virtual environment, and that virtual environment has been deactivated. If this is the case, reactivate with source bin/activate.