no module named error after installing with pip - python

I am trying to import matplotlib library, which I have installed via cmd: pip install matplotlib. And it installed successfully. But when I try to import matplotlib in jupyter lab, it gives me an error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-15-9738723f2bbd> in <module>
----> 1 import matplotlib as plt
2 from matplotlib import pyplot as pllt
ModuleNotFoundError: No module named 'matplotlib'
I checked both my python files and the installed matplotlib are in the same directory. Any ideas whats's wrong?

Sometimes happens that pip is installing the module for older python versions. Try to reinstall using pip3
Edit: as pointed out by MattDMo, on Windows they are both installed in the same folder. However, leaving this answer as this might be an issue in Linux.

Related

ModuleNotFoundError Despite being Installed

I'm having trouble loading a package that is installed in my environment and have no idea why..
conda list
fbprophet 0.3.post2 py36_0 conda-forge
When I request for libraries installed in conda, it clearly shows that I have fbprophet installed. Now, when I import it, a ModuleNotFoundError exception is thrown.
from fbprophet import Prophet
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-83be6864a7aa> in <module>()
----> 1 from fbprophet import Prophet
2 import numpy as np
3 import pandas as pd
ModuleNotFoundError: No module named 'fbprophet'
Has anybody run into this issue? What can I do to troubleshoot this?
My suggestion would be creating a virtual environment for your python first, then conda install your package in the virtual environment.
My script was reading from my pip install list where the module fbprophet did not exist. I went back and installed it there and everything worked. Lesson learned.
Always check where your libraries are being read from.
You may have more than one Python installation. Thus you might installed the library in one Python installation and tried to call it from another one. Please let me know if you have more than one Python installation by printing the result os this CMD command where python.

Spyder not finding modules installed with anaconda

I have a newly installed Anaconda and tried to run an old code that uses scipy, numpy and os using Spyder 3.2.6. and get an error. When trying to import numpy from the IPythoin console I get
import numpy as np
Traceback (most recent call last):
File "<ipython-input-4-0aa0b027fcb6>", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
The os module however does get imported and works. I tried running python importing both scipy and numpy and I don't have any issue. I'm running just one Anaconda environment, so there's no mistake there.
Assuming you're using Anaconda Prompt:
Try installing Spyder into that environment via "conda install spyder", and then run spyder from that environment via "spyder".
I had the same issue. I just wrote this line in Anaconda Prompt instead of OS command prompt:
pip install <module>
It's obvious that <module> will be replaced by the desired module name.

import matplotlib error on mac

Um... I wanted to import matplotlib in Python IDLE, but it said
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
I've already tried pip thing and the conda thing in terminal.
It said
# All requested packages already installed.
# packages in environment at /Users/Dan/anaconda:
Then! what's the problem here?
You may have installed Matplotlib to Python 2.7 and not Python 3.6. To install it to Python3 you need to use pip3:
pip3 install matplotlib
Then open python3.6 from your terminal (not idle) and try importing matplotlib from there. This way you can use any text editor you wish, and run your code from the terminal.
I had the same issue using the same command in IDLE. I just figured it out. go to your terminal and enter:
pip3.6 install matplotlib
I was using pip3 instead of pip3.6

ModuleNotFoundError: No module named 'twitter'

I am attempting to import a twitter api wrapper. I am using https://github.com/bear/python-twitter and have installed it using pip install python-twitter, when I run pip freeze into the command prompt it shows that I have python-twitter==3.2.1 installed however when I try to import it using import twitter in Jupyter QTConsole running Python 3.6.0, I get back this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-645f6dc1896f> in <module>()
----> 1 import twitter
ModuleNotFoundError: No module named 'twitter'
I am at a loss as to what is going wrong, the package doesn't say it's restricted to a certain version of python, and searching online hasn't helped. So now I am asking here in case anyone has a solution.
Turns out I had 2 versions of Anaconda installed and the package was defaulting to the wrong one, uninstalling the older version of anaconda and reinstalling the package fixed the problem.

Installing a package using pip or easy_install with ipython / conda

I'm trying to install 'frida' on my Anaconda environment, and although it installs fine, I keep getting an error when importing it from IPython:
In [4]: import frida
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-58e5c65e5010> in <module>()
----> 1 import frida
ImportError: No module named frida
On the normal python shell the import works fine. The problem is only with IPython.
I've tried using easy_install from the conda command line - no go.
I've tried this from an IPython shell:
In [5]: easy_install.main( ["-U","frida"] )
And the package install successfully, but IPython still gave an error when importing it.
pip doesn't find the package.
I seem to be missing something with the IPython packages - How does one install packages to IPython?
If you are working in virtualenv, then installing IPython into virtualenv resolve such problems.
Usually, IPython is giving this advice when it start inside of virtualenv.

Categories

Resources