unable to run matplotlib - python

on 64bit win 7, I installed all of compatible versions of setuptools, numpy, python-dateutil, pytz, pyparsing and six in addition to matplotlib. I did this by downloading source into a folder, and installing from source ... for example,
python setup.py install
finally, I installed python matplotlib by,
cd matplotlib
python setup.py build
python setup.py install
I tested matplotlib by running python from my windows powershell, and typing import pylab I got error:
ImportError: error importing numpy: you should not try to import numpy from its source ...
I found a stackoverflow question that addressed this, leading answer was to change working directory from the directory where numpy lives.
I changed the working directory to another folder in my drive, again ran python from my interpreter, typed import pylab and received this error:
ImportError: NO module named numpy"
I am now at a loss. It either refuses to import numpy, or says it doesn't exist? But it knew it existed earlier?
Ive been looking for a solution for more than three hours now, am stumped. Apologies in advance if this question seems too noob.
finally, I am open to trying a different module if it would be easier. I only want to plot some data.

Related

Importing python modules in vscode

Recently downloaded vscode on macOS, but I seem unable to import any python modules. I've made sure I'm using a python3 interpreter but can't find the problem. For example:
import numpy as np
returns
ModuleNotFoundError: No module named 'numpy'
and similarly for any other modules:
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I have downloaded homebrew although I don't understand what it is (I'm a physicist not a programmer) and so far spent a few hours trying to figure it out. Any help would be great.
Those two modules are third-part modules that need to be downloaded. The easiest/most common way to download is to use pip, which is a python module that should have come with your python install.
From the command line, run a python3 -m pip install numpy matplotlib. That will call python using the module pip, with the pip command 'install numpy maplotlib' (you can call them one-at-a-time if you like).
Once they are installed, you should be able to import them as you attempted above.
This happened to me before when I tried to download the flask module,all I did was restart my vs-code and everything was working

No module named 'matplotlib' Python

I am very new to programming so bear with me.
I am trying to import matplotlib . I have matplotlib already on my computer. When I
import matplotlib.pyplot as plt
I get
ModuleNotFoundError: No module named 'matplotlib'
I have tried to uninstall and reinstalled matplot lib using pip and pip3 multiple times. When I uninstall I get this and then reinstall I get this:
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\...
I have also tried uninstalling and reinstalling python but that doesn't seem to do anything.
What can I do to fix this? I am using the most recent version of Python.
If you have multiple python editors, make sure you installed matplotlib with the pip.exe from the python editor you are trying to import matplotlib.pyplot in.
Make the pip.exe you are using in a folder called Scripts is in the folder that contains to python editor of interest.
For example, the pip.exe from Pycharm could be 'C:\Users\User\jetbrains\AppData\Roaming\Python\Python37\Scripts', while the pip.exe from spyder could be 'C:\Users\User\Anaconda3\Scripts'.

"ModuleNotFoundError: No module named 'numpy'" for Python 3.7.3 on Mac

I am following instructions to make a very simple neural network program, and I keep getting an error from my line to import NumPy.
import numpy as np
I always get the following error:
ModuleNotFoundError: No module named 'numpy'
When I use the Mac console and type import numpy, it works fine.
When I am typing the import statement in PyCharm and type it slowly to see what intellisense suggests, it suggests "numbers" or "enum", but NumPy is not there.
When I use the Mac console, I can write import numpy without any problems.
I checked the class-path and it appears to include the Anaconda folders, which is where NumPy is.
Python version: 3.7.3
NumPy version: 1.16.4
macOS v10.14 (Mojave)
If you haven't installed NumPy like,
pip install NumPy
or
pip3 install NumPy
that will most likely be the answer.
If you have I would suggest reinstalling the NumPy package:
pip reinstall numpy
or
pip3 reinstall numpy
Another thing is just try to look at the NumPy page, and search for anything else that might help you!
Python looks for modules in every directory listed in sys.path. The Python binary (and module paths) are almost certainly different for PyCharm and the system installed (Terminal) environments.
You will have to install NumPy within PyCharm. Alternately, you can use sys.path.append(0,'/path/to/numpy') or (in Bash) PYTHONPATH=$PYTHONPATH:/path/to/numpy to temporarily extend the sys.path array to point to another distribution of NumPy on your system.
I tried uninstalling and reinstalling it, but there wasn't any difference.
Atom doesn't have any problem with the import statement. It's only PyCharm, so I will stick to Atom.

can't find brokenaxes module

I want to create a histogram with broken axes and found that there must be a module doing this called brokenaxes that works together with matplotlib (source) .
Anyway, when I trie to import the module like this:
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
I get this error message:
No module named brokenaxes
I'm using ipython5.1 in anaconda 4.3.
Can anyone help me?
In order to use a module it has to be installed. This can be done via
pip install brokenaxes
See https://docs.python.org/3/installing/
However, it seems that the brokenaxes you get from the python package index is currently (as of June 2017) broken (as the name says it ;-)). It should now (as of August 2017) be working again (see answer by package maintainer below).
Alternatively
go to https://github.com/bendichter/brokenaxes, download the files and copy
brokenaxes.py into your python's site-packages folder.
Package creator here. There was a bug in the install script. It worked despite the bug in previous versions of pip, but if you have the most recent version the install broke. I fixed it today, so you should be able to run:
pip install brokenaxes==0.2
to get the latest version. Sorry for the inconvenience and thanks for bringing this to my attention.
Ben

Cannot import matplotlib in Python 3

I want to install matplotlib on windows. To do this I tried those lines,
git clone https://github.com/matplotlib/matplotlib
cd matplotlib
py setup.py build
py setup.py install
which I found at this link
But I think the installation does not succesfully occured. This is result of py setup.py install:
So still following imports does not work;
import matplotlib.pyplot as plt
import matplotlib.animation as animation
An error says Unresolved import. So I am supposing this is because freetype and png did not installed.
Now I found freetype.dll and installed it but where should I put that file?
Any idea about this problem.
Yes. Matplotlib has some dependencies that need to be installed in order for the library to function fully. Quoting:
Once you have satisfied the requirements detailed below (mainly
python, numpy, libpng and freetype), you can build matplotlib:
cd matplotlib python setup.py build python setup.py install
To be sure of the correct procedure check the build instructions. If this process seems somewhat complex (it sometimes is) you can consider Python distributions such as:
1) WinPython
2) Python XY
3) Anaconda
, that already bring several libraries by default and making it a lot easier to work with Python (and extensions).

Categories

Resources