I have installed a python library called PyRadiomics by doing:
pip install pyradiomics
When I do pip freeze | grep pyra
in the command prompt, I see pyradiomics==2.0.0
clearly showing that the library was installed.
When I start a python interpreter and do import pyradiomics
, it does not work. I realized that I need to do import radiomics
.
I just happened to figure this out by luck.
How is someone supposed to know how to import a library into their python script after installing it using pip. It seems that currently, you could install a library with pip install some_name
and have to do import some_other_name
in your Python code. I have been using Python for a while but never came across this before which lead me to assume that some_name
is always the same as some_other_name
but I found out that this is not the case.
How is someone supposed to know what that other name is after installing a library called some_name
pip
can list installed files for any package installed by it:
$ pip show -f packagename
Doing some simple output filtering/transforming with bash, you can easily come up with a custom command that will list all Python packages/modules in a package, for example:
$ pip show -f packagename | grep "\.py$" | sed 's/\.py//g; s,/__init__,,g; s,/,.,g'
Example output with the wheel
package:
$ pip install wheel
...
$ pip show -f wheel | grep "\.py$" | sed 's/\.py//g; s,/__init__,,g; s,/,.,g'
wheel
wheel.__main__
wheel.archive
wheel.bdist_wheel
wheel.egg2wheel
wheel.install
wheel.metadata
wheel.paths
wheel.pep425tags
wheel.pkginfo
wheel.signatures
wheel.signatures.djbec
wheel.signatures.ed2551
wheel.signatures.keys
wheel.tool
wheel.util
wheel.wininst2wheel
You can even alias it to a custom shell command, for example pip-list-modules
. In your ~/.bashrc
(Linux) / ~/.bash_profile
(MacOS):
function pip-list-modules() {
pip show -f "$@" | grep "\.py$" | sed 's/\.py//g; s,/__init__,,g; s,/,.,g'
}
Test it:
$ pip-list-modules setuptools wheel pip # multiple packages can passed at once
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With