I have installed python 3.5 on a computer running Scientific Linux 6.5. I have set up a virtual environment, and I have installed numpy and pylab using pip version 8.1.2.
My problem is this, when I try to do the simplest of tasks, i.e. import plot from pylab, I get this:
$ python
Python 3.5.1 (default, May 10 2016, 12:41:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pylab import plot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'plot'
>>>
Here is some other information:
>>> pylab.__version__
'0.1.0'
>>> matplotlib.__version__
'1.5.1'
>>>
I don't find any help through Google, and the only question similar to this doesn't seem relevant to me. What is going on?
After coming back over a weekend break and trying again with iPython, I got a different error message, which led to another Google search...
I found the answer here: Pylab - 'module' object has no attribute 'Figure'
My mistake was to think that pip install pylab would work as expected!
Installing pylab installs matplotlib, which apparently also installs pylab. This recursion causes the error. For me, uninstalling pylab and matplotlib and re-installing matplotlib alone fixed the error. I hope this helps!
Related
While running on my virtualenv I wrote this code on terminal and plot via matplotlib and shows me a 'Figure 1' named window with no drawing/content and throws 'TypeError' meanwhile:
(cv) pi#raspberrypi:~ $ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> x=[1,2,3,4]
>>> y=[2,4,6,8]
>>> plt.plot(x,y)
[<matplotlib.lines.Line2D object at 0x6fd4ca10>]
>>> plt.show()
TypeError: Couldn't find foreign struct converter for 'cairo.Context'
TypeError: Couldn't find foreign struct converter for 'cairo.Context'
TypeError: Couldn't find foreign struct converter for 'cairo.Context'
TypeError: Couldn't find foreign struct converter for 'cairo.Context'
I'm using Stretch version of RaspBian. I had installed matplotlib with sudo pip install matplotlib and tried this, also installed some dependent packages. What can I do?
Secondly are there any other way to draw histogram of image in opencv without matplotlib library?
I'm using python 2.7 on ubuntu 16.04. As described in the code below, I can't use any function from the np.matlib, but after I import, then it can be used. Is there any way to troubleshoot the problem? Thanks in advance!
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.matlib.repmat([1,1],1,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'matlib'
>>> import numpy.matlib as npm
>>> a = npm.repmat([1,1],1,2)
>>> print a
[[1 1 1 1]]
>>>
I think this is a library clash, and if so, how do I know which clashes against which?
The Python import system does not automatically load submodules of a package when a package is imported. NumPy's __init__.py does automatically load most NumPy submodules on a plain import numpy, but numpy.matlib is not included.
Until some code somewhere in the program explicitly imports numpy.matlib, numpy.matlib will not exist, and its contents will not be accessible.
import numpy.matlib as npm
This does not introduce the name numpy.matlib into the namespace; it only introduces the name npm. Python 2.7 doc reference.
If you want the module to be available through both numpy.matlib and npm, you can just define it that way, i.e. npm = numpy.matlib.
I installed opencv using brew and it seemed to install fine. I installed numpy, Scipy and Matplotlib with no problems. I run python and import these modules with no error. But opencv has been a real pain in the neck. I've spent hours try to get this to work.
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import opencv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named opencv
It almost seems like homebrew did not put the opencv module in the right directory.
Mike
the module is not named opencv, but cv2, so :
>>> import cv2
>>> cv2.getBuildInformation()
[EDIT]
if you're trying to run something like this ,
then there's bad news for you. opencv comes with it's own python bindings since a very long time now, but apart from that, there exist several outdated 3rd party bindings. the code you're trying to run seems to use one of those, so you can't use it with opencv's builtin api.
I am using Python 2.7.1+ in my Ubuntu 11.04 natty laptop. I installed nltk and all the dependencies to plot graph:
matplotlib==1.1.0
nltk==2.0b9
numpy==1.5.1
scipy==0.8.0
However, when I try to plot a graph (as follows), nothing is showing up (no error code as well):
user#user-laptop-ubuntu:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.plot(range(10), range(10))
[<matplotlib.lines.Line2D object at 0x2770fd0>]
>>> plt.title("Simple Plot")
<matplotlib.text.Text object at 0x2607610>
>>> plt.show()
>>>
or, this code:
>>> from nltk.book import *
>>> text4.dispersion_plot(["citizens", "democracy"])
Funny thing is, I have the same configuration in my desktop Ubuntu 11.04 and the plot is showing up there. I have similar libraries installed in both the computer.
I am totally puzzled now. Any suggestion will be cordially welcomed :-)
Gias
import matplot.pyplot as plt
from nltk.book import *
text4.dispersion_plot(["citizens", "democracy"])
plt.show()
I dont understand your question. But this trick works for me to plot nltk dispersion plot. Explain your question in detail.
Thank You
I'm installing PyQt4 on an old Linux system (CentOS 4.4) that can't be upgraded for hardware compatibility reasons. I've got Python 2.6, QT4 and SIP installed, and the installation of PyQt4 didn't give me any errors.
When I run Python, this happens:
Python 2.6.2 (r262:71600, May 11 2011, 14:18:37)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4
>>> import PyQt4.Qsci
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Qsci
I looked around, and found /usr/local/lib/python2.6/site-packages/PyQt4/uic/widget-plugins/qscintilla.py, which is almost empty of non-comment stuff:
pluginType = MODULE
def moduleInformation():
return "PyQt4.Qsci", ("QsciScintilla", )
Any ideas?
You need to install qscintilla separately. If PyQt is already installed, then you should just have to install the qscintilla python bindings. Hopefully this fixes your issue!