How to fix errors importing modules on python3 - python-3.x

I successfully import modules on python but I keep having the same output error ModuleNotFoundError: No module named '' error.
I installed matplotlib, eyeD3 and mutagen several times within the mac terminal:
#I used this code to install matplotlib on mac terminal
pip install --user matplotlib
#I used this code to install eyeD3 on mac terminal
pip install eyeD3
As I try to import matplotlib like the code below (or eyeD3) I get that Traceback error.
#to import matplotlib for example
import matplotlib.pyplot as plt
x = [1,2,3]
y = [2,4,1]
plt.plot(x, y)
plt.xlabel('x - axis')
plt.ylabel('y - axis')
plt.title('My first graph!')
plt.show()
All of the modules listed above installed correctly, but when I import one of the modules I get the same common error ModuleNotFoundError: No module named ''

I think you have at least 2 version of python on your computer.
When you write pip install matplotlib, it install matplotlib on python.
But when you start the programm, an other version of python is launch.
To fix it :
The command python -m pip install matplotlib will install matplotlib on the version that you want.
If you want to use python 3.X, just write python3 -m pip install matplotlib
If you want to use the last version that is install on your computer, write py -m pip install matplotlib.
You can do that for every module that you have to install.
I hope it will help you.

Related

Issue with importing Seaborn

When I try to import seaborn the import give me the below error message:
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import seaborn
ModuleNotFoundError: No module named 'seaborn'
I have tried the below steps to install:
pip install seaborn
python -m pip install seaborn
!conda install seaborn
%%bash pip install seaborn
pip3 install seaborn
conda install seaborn
sudo pip install utils ...and then install seaborn again
pip uninstall scipy and then install scipy package again.
These are the solutions I found, I closed iTerm and started it again and none of these worked.
Make sure you have Python and pip installed on your computer. Reinstall it if you have it. Try pip install seaborn. Also, make sure you are installing it in the same directory as where you are working. If that issue still persists, there must be a problem with your shell or computer.
PS:
If you are using Juypter Notebook do in a cell:
import sys
!{sys.executable} -m pip install seaborn

Mac OS X: "ModuleNotFoundError: No module named 'numpy'"

After I have reinstalled Anaconda, I can not import NumPy any more on Python 3:
import numpy as np
Output:
ModuleNotFoundError: No module named 'numpy'
I have tried
pip install numpy
I try to install it again, but I get:
pip install numpy
Output:
Requirement already satisfied: numpy in /anaconda3/lib/python3.7/site-packages (1.16.3)
Screenshot of some of the above
This command worked for me
python3 -m pip install numpy
You probably have multiple NumPy versions installed on your system and need to manually delete the old one.
Open Terminal and run:
pip list
Remember or notate the NumPy version from the list
Then run Python in Terminal or write and execute this code in your IDE:
import numpy
print(numpy)
print(numpy.version)
This should print two lines: numpy package location + numpy version like this:
<module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy/init.pyc'>
1.16.1
If the NumPy version reported here is different than the one reported by pip list, then go to the NumPy package location printed above and delete that package folder
Try importing NumPy now. If you previously installed it, it should work. If you didn't install it then go and install it now. After installation all should work fine.
You are using a Conda environment to run your program. So you should run:
conda install numpy
If you use IDE like PyCharm, it will be easy to install packages by a mouse click (Install packages).

No module named 'pandas_datareader' in Jupyter (Anaconda) after I run pip3 install pandas_datareader

I am trying to learn pandas and want to load some stocks data. I was following a course which advised me to load pandas.io.data, but this did not work as io.data was depreciated. So I decided to use pandas-datareader instead. But I am struggling to instal it on mac in Anaconda (Jupiter notebook).
First time I run import pandas_datareader as pdweb I got ModuleNotFoundError: No module named 'pandas_datareader'. Not surprising as I never used this before so I run pip3 install pandas_datareader in Terminal which successfully installed itself. However, Jupiter notebook is still giving me the same error. At this point, I tried running in Terminal conda install -c https://conda.anaconda.org/anaconda pandas-datareader but it did not work as -bash: conda: command not found.
Please help. I am looking for a detailed explanation as I am not too techie.
What I run in Jupiter
import numpy as np
from pandas import Series, DataFrame
import pandas as pd
import pandas_datareader as pdweb
import datetime
Result
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-da568f513c93> in <module>
2 from pandas import Series, DataFrame
3 import pandas as pd
----> 4 import pandas_datareader as pdweb
5 import datetime
ModuleNotFoundError: No module named 'pandas_datareader'
Just run
conda install -c anaconda pandas-datareader
as per instructions here.
In my experience, if you're using conda, you should never install with pip unless you're sure conda doesn't have it. Try searching anaconda.org to see which -c source to use.
The problem was with conda command not being set up during the installation of Anaconda. I solved this by removing Anaconda with App Cleaner & Uninstaller Pro (free soft) and reinstalling later version.
After reinstallation of Anaconda command below worked like a charm.
conda install -c anaconda pandas-datareader
If you using Anaconda and still have issues installing panads-datareader using the conda command 'conda install -c anaconda pandas-datareader'. or the installation is successful but the import pandas_datareader.data as web still gives an error.
Locate where your 'site-packages % ' directory and cd to the site-packages % dir and then run the installation command 'conda install -c anaconda pandas-datareader '. It will work.
For the install, try using
pip
instead of
pip3

import pandas as pd error - module 'matplotlib' has no attribute 'artist'

I have a single line shell in jupyter notebook
import pandas as pd
Which on running produce the error
module 'matplotlib' has no attribute 'artist'
Doesn't these two packages 'matplotlib' and 'pandas' independent? Why am i getting this error?
This is a known issue on GitHub. Pandas relies on matplotlib for its plotting functions. To fix it, run this in your jupyter terminal to update to the newest version of both modules:
python -m pip install --upgrade matplotlib pandas
it still exists after run
python -m pip install --upgrade matplotlib pandas
then create a file ~/.matplotlib/matplotlibrc and add the following code:
backend: TkAgg

Module 'matplotlib' has no attribute 'colors'

I am running an Anaconda installation of Python3 64bit on Windows. I have no idea how to put those words in a proper sentence, but I hope it gives enough information. I am taking an Udacity course which wants me to run %matplotlib inline. This gives the following error:
AttributeError: module 'matplotlib' has no attribute 'colors'
I get the same error when I run from matplotlib import pylab, but i get no error from import matplotlib.
I installed matplotlib as follows: conda install -n tensorflow -c conda-forge matplotlib.
How do I solve this error?
Kind regards
Per request:
conda list gives
matplotlib 2.1.0 py36_1 conda-forge
and a list of other modules.
The notebook needs to be restarted for the new installations to take effect.
You just need to upgrade matplotlib.
pip3 install -U matplotlib

Resources