No module named 'matplotlib.pyplot'; 'matplotlib' is not a package - python-2.7

Have found a similar issue, however haven't found proper solution.
Here's a code:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,2,5])
plt.show()
Run, got the message:
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I run Linux Mint 18 with preinstalled python-2.7 and python-3.5 (I use python3), before that I was installing modules with a simple sudo apt-get install method and that worked great.
Before running this the code above, I've installed matplotlib in a usual way sudo apt-get install python-matplotlib. As it haven't worked out, started to look for solution.
Python location
which python3 /usr/bin/python3
Current Matplotlib installed
sudo find /usr | grep matplotlib /usr/lib/python3/dist-packages/matplotlib
My tries:
1) I've removed matplotlib with autoremove, and tried to make it sudo apt-get install python3-matplotlib instead. Didn't worked out.
2) Used: pip3 install matplotlib or sudo pip3 install matplotlib. Received errors like:
command python setup.py egg_info failed with error code 1 in /tmp/pip-build- ....
3) Then I found another solution:
sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install matplotlib
Same outcome.
Haven't tried to use import sys sys.path.append('/usr/lib/pymodules/python2.7/')(proposed in link above), but as I am not sure what exactly this command does (quite a newbie to python and programming itself) - haven't risked.

If you are using pycharm and have matplotlib.py in your current working directory than you get this error. Just delete or rename the matplotlib.py file and it will work.

don't name any file as matplotlib.py within your working directory

In your working directory, check if there is any file matplotlib.py
Delete that file and import matplotib again. That should work.

simply install:
python -m pip install -U pip
python -m pip install -U matplotlib

I had the same problem reasons in my case were
python 3.8.2 with matplotlib that I downloaded was for 3.7. Make sure they are the same.
python 64 bits version with matplotlib 32bits. Make sure they are the same
Use python -m pip install package_which_you_need to install packages for Windows
Make sure to add to PATH the environment variables I forgot to do in my case
pip version was old use
Use python -m pip install --upgrade pip to upgrade pip to the latest for Windows
I saved the file name as matplotlib.py. Try to avoid that
Finally I typed matplotlib.pyplot as matplotlib.plyplot remember to check for typos first. The error message looks similar even though I corrected all the steps above.
ModuleNotFoundError: No module named 'matplotlib.pyplot'
ModuleNotFoundError: No module named 'matplotlib.plyplot'

Related

ImportError: No module named 'skimage', but i have all dependencies and scikit-image installed

I tried to run a program in python3.4, but it always give me this error message
from skimage import feature
ImportError: No module named 'skimage'
I search the internet for answers here and there, tried some solutions, but i keep getting the error. But then I tried to run the exact same program in python2.7, and it did not give any error mesaage so I assume that it runs well in python2.7. Is there anyway I can get this program running in python3.4?
You have it installed in your Python 2 libraries. You should install it in your Python 3 libraries too:
$ pip3 install scikit-image
I had the same problem, I have the scikit-image package installed in Python 3 and when I ran:
$ ./<filename.py>
I got the same error. Turns out Python 2 was running. Try running:
$ python3 ./<filename.py>
If you have installed python via Anaconda, you can run the following. It fixed the error.
conda install --yes -c conda-forge scikit-image
I tried every possible method within the environment but failed terribly until I used sudo.
What did work:
sudo pip install scikit-image
What didn't work
pip install scikit-image
conda install scikit-image
conda install -c anaconda scikit-image
conda install --yes -c conda-forge scikit-image
pip3 install scikit-image

Missing pip in python 2.7?

I am attempting to install a module (requests) in python 2.7.4 but am unable to do so because apparently I don't have pip installed? I tried to run "python pip --version" in CMD to check for it and got nothing in return except that pip is not a recognized command.
Have been googling the past 20 minutes and have tried each suggestion to no avail. Sorry for the stupid question but this is quite infuriating.
Python 2.7 must be having pip pre-installed.
Try installing your package by:
Open cmd as admin. (win+x then a)
Go to scripts folder: C:\Python27\Scripts
Type pip install "package name"
Note: Else reinstall python: https://www.python.org/downloads/
Also note: You must be in C:\Python27\Scripts in order to use pip command, Else add it to your path by typing: [Environment]::SetEnvironmentVariable("Path","$env:Path;C:\Python27\;C:\Python27\Scripts\", "User") For New versions
Older versions of python may not have pip installed and get-pip will throw errors. Please update your python (2.7.15 as of Aug 12, 2018).
All current versions have an option to install pip and add it to the path.
Steps:
Open Powershell as admin. (win+x thena')`
Type python -m pip install <package>.
If python is not in PATH, it'll throw an error saying unrecognized cmd. To fix, simply add it to the path as mentioned above.
The new version of python is already contains pip. I feel that you yet not set the environment path. just set environment path and try again.
If the issue still exists you just install pip using typing the following command in CMD
python -m pip install.
According to this answer
Good news! Python 3.4 (released March 2014) and Python 2.7.9 (released December 2014) ship with Pip.
so perhaps updating to 2.7.9 will solve your problem. Or you could follow some of the other suggestions in that answer to install pip manually.
For Ubuntu
sudo apt install python3-pip
or
sudo apt install python-pip
Try this instead, if you are using windows OS type in command line ".\pip " and whatever command you want to use after, it can be install uninstall etc.

Pip installation bug

So I tried to install pip using the get-pip.py file, and when I ran the file, terminal told me I already had pip installed on 2.7. However, when I try to find the version of my pip, terminal tells me pip doesn't exist and points to a version of 3.5 I have installed. Clearly my issue is that I have pip installed on v2.7 but the pip command is linked to v3.5. Any clues on how to fix?
Here's a picture of my terminal output:
To install a package in a particular version of python, use the following commands always:
For python 2.x:
sudo python -m pip install [package]
For python 3.x:
sudo python3 -m pip install [package]
This should resolve the doubt of which python version is the given package getting installed for.
Note: This is assuming you have not created aliases for the python command

Python3 pyserial library

I am working on small python scripts. Basically i am not a python programmer and very new to it. Recently i have been working on IOT protocol MQTT. I have installed a open source MQTT clinet based on python3 in my raspberypi board. And now i am facing a problem. I have python 2.7 and 3.2 installed.
My MQTT client work with Python3.x and i want to use pyserial library also which i am not able to , i am getting a error
Serial module not found
I goggled a bit and end up here.. Now it say that you need to install pip3 in order to install pyserial for python3.x.
I tried to install pip3 using this link , but end up installing pip2 using
pip install -U pip
I feel totally being messed up now. I just want to use pyserial while working with python3.x version.Can any one suggest me how?
Edit 1:
On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
I recently came through this documentation given here . But it even give a error to me /usr/bin/python3 : NO module named pip. main : 'pip' is a package and cannot be installed directly.
Assuming you're using raspbian on your pi, you could install pip3 from the normal repositories:
apt-get install python3-pip
You can get the serial module the same way:
apt-get install python3-serial
I succeeded installing pyserial2.7 on a Mac running Yosemite and Python3.4
I entered the pyserial-x.y directory and run:
python3 setup.py install
I got lot of errors that I corrected one by one by editing the files containing the syntax errors. Only 2 types of errors are encountered:
- print needs ()
- except needs as instead of ,
So by correcting the dozen of errors with some patience, installation finish correctly.
I wonder why a syntactically correct version for Python3 is not ready!

How do I get the path of a package installed with PIP, and chang that path?

I installed virtualenv with PIP.
pip install virtualenv
Everything appeared to go smoothly. When I enter
$ pip freeze
it lists
virtualenv==1.10.1
I can import it with python just fine
$python
...
>>> import virtualenv
>>>
Yet when I try to create a virtual env:
$virtualenv test
-bash: virtualenv: command not found
I assume this is because of my Path, but I am not sure how to find the path or change it. How do I fix this?
If I do
$sudo find /- virtualenv
/usr/local/share/python/virtualenv
When I do
brew info python
I get
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
Which is not where virtualenv is. This seems to happen with everything I've loaded with PIP lately. Is there a universal fix to get the directory PIP installs to line up with the directory Python thinks its installing?