ModuleNotFoundError: No module named 'Ipython' - python

I'm trying to parse the following line of code in an iPython notebook.
from Ipython.display import display, Image
I get the following error,
ModuleNotFoundError: No module named 'Ipython'
When I run pip3 install Ipython
Here's what I get.
Requirement already satisfied: Ipython in ./.envs/dl/lib/python3.6/site-packages
I'm running the code in the same virtual env in which ipython is installed. What am I missing. My python version is 3.6.

Its from IPython.display import display, Image
'P' also caps in IPython

I had this problem too. You have to pay attention to which python version you are using, which pip version, and which environment too. I made a stupid mistake at first and installed TensorFlow on a virtualenv, then tried to call IPython which means my function and installation had different paths.
I recommend using "python -m pip install"

Related

Pip installed a module I want to use, but still getting "module not found" error

I am trying to use the Python module Gdal. I have run pip install gdal and I recieve the message
Requirement already satisfied: gdal in c:\users\willy\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (3.3.1)
and yet when I run import gdal in my Python IDE (I use Spyder), I still get the error no module named gdal
You need to tell Spyder which Python interpreter to use. Point it to the one you're installing the package for, as it seems that it's using a different one.
https://docs.spyder-ide.org/current/faq.html#using-existing-environment
From the documentation it seems you have to call:
from osgeo import gdal
See here
Answer is here in Spyder docs: https://docs.spyder-ide.org/5/faq.html#using-packages-installer
Don't try to use pip install and expect it to work in Spyder. Follow these instructions

Jupyter Notebook ModuleError after Homebrew Upgrade

I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.

Installing modules like pygal so they work in Spyder

I'm a Python beginner working with Spyder, who must pip install modules for my class; pygal, for example. When I try to install, or reinstall as an administrator, this is what I get:
C:\WINDOWS\system32>pip install pygal
Requirement already satisfied: pygal in c:\users\flora\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (2.4.0)
Yet when I try to import the module in a Spyder file, this is the message I get:
Traceback (most recent call last):
File "C:\Users\flora\crash python\data mining\world_population2.py", line 2, in
import pygal
ModuleNotFoundError: No module named 'pygal'
And there's no sign of it in the dependencies in Spyder. Same thing using IDLE 3.8. I had assumed that Spyder or Anaconda would automatically be able to use it. Does it have something to do with WHERE I have saved it? I have tried reinstalling Anaconda, restarting my computer, etc. No difference.
Thanks in advance for any ideas.
No idea if this will help but if you goal is to use pygal you can try using a different ide with python build in. It does not run the most current version of python by default but you can change it to the version of python you have installed.
Try using Thonny I was able to import and run some code from pygal.

Importing matplotlib returns "ModuleNotFoundError" after installing matplotlib with pip

I'm trying to display data using a pie chart in python, so i tried to install matplotlib using pip. After doing that, I tried importing matplotlib but I get an error: ModuleNotFoundError: No module named 'matplotlib'.
In the Command Prompt I typed 'pip install matplotlib' and everything appeared to be successful. This is the last line:
Successfully installed backports.functools-lru-cache-1.5 cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.4 numpy-1.16.2 pyparsing-2.3.1 python-dateutil-2.8.0 pytz-2018.9 six-1.12.0
I've also tried 'python -m pip install -U matplotlib', but I still get a ModuleNotFoundError.
I've tried running the input statement in both python 3 and 2, neither worked.
I've looked at various different discussions on this, and none of them seemed to help me. How can I fix this?
There are various python installed in your OS. If you install matplotlib for somewhere the python that you are using does not search, you get importing errors. You should figure out which python you want to use and where the packages it searches.
check your python path. the matplotlib should be installed in the same path with your python environment.
I guess you use an IDE to run the python. some IDE have their own python environment.
if not solved. plz introduce some details about your system、how installed etc.

I installed matplotlib successfully but when I try to import it it gives an error with 'no module named matplotlib'

I installed python 3.7 on my pc (win 10). Later I tried to install matplotlib using a pip command, it installed and matplotlib is now also inside the pip list. When I go to the lib/site-packages folder where I saved python, it clearly has matplotlib inside of it. matplolib also works when us it in my command promt after using the 'python' command. But when I wanna import it in my project in pycharm, it does not work and no module is found.
I am new to all this and this is the first module I installed for python, so I can not figure out what I am doing wrong here. The version of matplotlib I am trying to install is 2.2.3.
Thx for any help

Categories