I suspect that the pip
executable might be pointing the a different version of python than what you're currently using in your notebook.
You might try running pip using the %pip
magic function instead of running the inline shell command !pip
, i.e.
%pip freeze
and
%pip install your-missing-package
Explanation
%pip
is a line-magic function that uses the current executable (sys.executable
).
In contrast, !anycommand ...
runs the shell command:
sh anycommand ...
using the old-school sh
shell interpreter (not bash
as you might expect). Therefore, it is possible that the system executable pip
that you're running (via !pip ...
) uses a different version of python from sys.executable
.
Alternative
Alternatively, if this doesn't work, you could use sys.executable
in your shell command (in a notebook cell):
import sys
!{sys.executable} -m pip freeze
Similarly, to install packages, you might want to run:
!{sys.executable} -m pip install your-missing-package
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…