ImportError: No module named nibabel in python 2.7 - pytorch

I am using python 2.7 and I used
pip install nibabel
but I constantly get the error
ImportError: No module named nibabel.
when I type
pip show nibabel
I get this result so it seems that it is installed but still get the aforementioned error when using import nibabel as nib
Name: nibabel
Version: 2.5.0
Summary: Access a multitude of neuroimaging data formats
Home-page: https://nipy.org/nibabel
Author: nibabel developers
Author-email: neuroimaging#python.org
License: MIT License
Location: /usr/local/lib/python3.5/dist-packages
Requires: six, numpy
Required-by:
Here the address shows it is installed in python3 path! How can I address this problem?

Install it using pip2:
pip2 install nibabel
Or explicitly call the pip module for Python 2.7:
python2.7 -m pip install nibabel
for example.

Related

iterative.ai MLEM | ModuleNotFoundError: No module named 'mlem.api'; 'mlem' is not a package

Goal: install and run Python script with MLEM code.
Following this installation guide in the library docs; pip install mlem should suffice.
Code:
from mlem.api import import_object
# ...
Traceback:
$ python3 app/deployment-poc/mlem.py
Traceback (most recent call last):
File "/home/me/BitBucket/project/app/deployment-poc/mlem.py", line 1, in <module>
from mlem.api import import_object
File "/home/me/BitBucket/project/app/deployment-poc/mlem.py", line 1, in <module>
from mlem.api import import_object
ModuleNotFoundError: No module named 'mlem.api'; 'mlem' is not a package
I've installed both via pip and conda.
$ which mlem
/home/me/miniconda3/envs/venv/bin/mlem
$ mlem --version
🐶 MLEM Version: 0.4.1
$ conda list
# packages in environment at /home/me/miniconda3/envs/venv:
#
# Name Version Build Channel
fastapi 0.89.1 pypi_0 pypi
mlem 0.4.1 pypi_0 pypi
(venv) me#laptop:~/BitBucket/project$ pip install mlem --no-dependencies
Requirement already satisfied: mlem in /home/me/miniconda3/envs/venv/lib/python3.10/site-packages (0.4.1)
(venv) me#laptop:~/BitBucket/project$ pip show mlem
Name: mlem
Version: 0.4.1
Summary: Version and deploy your models following GitOps principles
Home-page: https://mlem.ai
Author: Mikhail Sveshnikov
Author-email: mike0sv#iterative.ai
License: Apache License 2.0
Location: /home/me/miniconda3/envs/venv/lib/python3.10/site-packages
Requires: aiohttp, aiohttp-swagger, cached-property, click, cloudpickle, dill, entrypoints, flatdict, fsspec, gitpython, importlib-metadata, isort, iterative-telemetry, Jinja2, pydantic, pyparsing, python-gitlab, python-multipart, requests, rich, typer
Required-by:
Request to have a reputable member create new tag: mlem
You have a script /home/me/BitBucket/project/app/deployment-poc/mlem.py which shadows importable package mlem. With such a script import mlem in the script tries to import from the very script, not from the package.
Rename mlem.py to something different.
The bottom line: never name you scripts the same as importable packages. Never have email.py or test.py, etc.

Modules installed globally not found in VS Code Jupyter Notebook

I've installed several Python modules from PyPi globally on Mac OS using pip3. Running pip3 list confirms that they are installed:
user#users-MacBook-Pro SER-neural-net % pip3 list
Package Version
------------------ ---------
appdirs 1.4.4
audioread 3.0.0
...
librosa 0.9.2
numpy 1.23.4
pip 22.3.1
scikit-learn 1.1.3
scipy 1.9.3
sklearn 0.0.post1
sounddevice 0.4.5
soundfile 0.11.0
torch 1.13.0
...
From the integrated terminal in VS Code where I am running the notebook, I have run the following commands to determine which Python interpreter to use:
user#users-MacBook-Pro SER-neural-net % which pip3
/usr/local/bin/pip3
user#users-MacBook-Pro SER-neural-net % which python3
/usr/local/bin/python3
user#users-MacBook-Pro SER-neural-net % python3 --version
Python 3.7.9
I have selected the appropriate interpreter at the top right of Jupyter Notebook view in VS Code:
But the modules confirmed to be installed for this interpreter are not found:
What has gone wrong?
use this:
python3 -m pip install --user (library)
for example:
python3 -m pip install --user pandas

'import' showing outdated versions after updating to Python 3.10 on Google Colaboratory

after updating from Python 3.7 to 3.10 on Google Colaboratory when using pip the newly installed packages arent showing when using 'import'. There's a demo at Colab on this link
I Updated the python version using this
!wget https://github.com/korakot/kora/releases/download/v0.10/py310.sh
!bash ./py310.sh -b -f -p /usr/local
!python -m ipykernel install --name "py310" --user
!python --version
And installed numpy using
!pip3 install numpy==1.22.4 --upgrade
Thing is, the newly installed version of numpy is showing on pip, at the python3.10/site-packages folder
!pip show numpy
Name: numpy
Version: 1.22.4
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /usr/local/lib/python3.10/site-packages
Requires:
Required-by: pandas, torchvision
But import is using the preinstalled version on 3.7/dist-packages.
using
import numpy
numpy.__version__
outputs
'1.21.6'
and
numpy.__config__
outputs
<module 'numpy.__config__' from '/usr/local/lib/python3.7/dist-packages/numpy/__config__.py'>
Re-starting the runtime to clear the cached versions of the packages didn't help either.
There's a way to detect and prioritize the packages on the Python3.10 folder?

Simple standard command line test to verify Python module is successfully installed

Is there a simple test from the command line (zsh Catalina / bash Ubuntu) that verify installation of a python module?
For example: if pip3 install reportlab is executed, does execution of from the python prompt:
'>>> import reportlab
positively confirm that module is successfully installed? What are the limits (false positives) of this test?
pip show followed by the name of the package.
For example:
pip show pyyaml
Will output something like this:
Name: PyYAML
Version: 5.3.1
Summary: YAML parser and emitter for Python
Home-page: https://github.com/yaml/pyyaml
Author: Kirill Simonov
Author-email: xi#resolvent.net
License: MIT
Location: d:\_venvs\python36\test-geo\lib\site-packages
Requires:
Required-by: yamllint
You can also use pip list and pip freeze to display a list of installed packages.

Python package installation

I am trying to install nibabel through pip:
pip install nibabel
It installs successfully, however, when I write the following code:
import nibabel as nib
I get this error :
ImportError: No module named 'nibabel'
And when I check in the terminal using:
pip show nibabel
It shows that it exists
Author-email: neuroimaging#python.org
License: MIT license
Location: /usr/local/lib/python3.6/site-packages
Requires: numpy, six
This issue happens in both Python 3.x and 2.x.
Here's what you can do:
If you're using Python 2.7, you might need root permission to install the nibabel module.
Try this:
pip install nibabel --user
Hopefully, you should get this Successfully installed nibabel-2.2.1 message.
Then, run your Python 2.7 environment and:
import nibabel as nib
If this doesn't help, you might want to try virtualenv.
Finally, double check if you meet the nibabel requirements e.g. Python 2.7, or >= 3.4.

Resources