I'm using Python 2.6 in Ubuntu 10.10.
I've run help("modules") in the Python interpreter and pylab and matplotlib are installed.
However, when I run import pylab, I get the following error message.
>>> import pylab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/lib/pymodules/python2.6/matplotlib/pylab.py", line 206, in <module>
from matplotlib import mpl # pulls in most modules
File "/usr/lib/pymodules/python2.6/matplotlib/mpl.py", line 3, in <module>
from matplotlib import axes
File "/usr/lib/pymodules/python2.6/matplotlib/axes.py", line 7928, in <module>
Subplot = subplot_class_factory()
File "/usr/lib/pymodules/python2.6/matplotlib/axes.py", line 7920, in subplot_class_factory
new_class = new.classobj("%sSubplot" % (axes_class.__name__),
AttributeError: 'module' object has no attribute 'classobj'
I don't know what's happening or how to fix it.
Any help is appreciated.
http://old.nabble.com/scipy,-matplotlib-import-errors-td16343711.html
You have a new.py somewhere?
Creating a new.py file anywhere near where you are calling pylab module will break pylab and return this exact error.
Related
I'm attempting to use Xlwings for Python, however having installed Python 3.5, pywin32 extensions and Xlwings I get the following error when starting import:
from xlwings import workbook
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from xlwings import workbook
File "C:\Python 3.5\lib\site-packages\xlwings\__init__.py", line 18, in <module>
from . import _xlwindows as xlplatform
File "C:\Python 3.5\lib\site-packages\xlwings\_xlwindows.py", line 15, in <module>
import pywintypes
File "C:\Python 3.5\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Python 3.5\lib\site-packages\win32\lib\pywintypes.py", line 117, in __import_pywin32_system_module__
assert sys.modules[modname] is not old_mod
AssertionError
Try commenting out the asserts (replace them with a pass) and see if it works. Otherwise you're going to need to debug pywintypes.
Felix Zumstein just informed me that the above suggestion won't work:
When you comment out those lines, then it fails further down when doing from pywintypes import TimeType: ImportError: cannot import name 'TimeType'
However, downgrading may solve this problem.
After Much trial and error ive found that downgrading to Python 3.3 works
Thnak you for all the responses
I'm trying to use matplotlib on Cloud9 ide, but here's what happens:
>>> import matplotlib
>>> matplotlib.use('Agg')
>>> from matplotlib import pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 24, in <module>
import matplotlib.colorbar
File "/usr/lib/pymodules/python2.7/matplotlib/colorbar.py", line 29, in <module>
import matplotlib.collections as collections
File "/usr/lib/pymodules/python2.7/matplotlib/collections.py", line 23, in <module>
import matplotlib.backend_bases as backend_bases
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 50, in <module>
import matplotlib.textpath as textpath
File "/usr/lib/pymodules/python2.7/matplotlib/textpath.py", line 5, in <module>
import urllib
File "/usr/lib/python2.7/urllib.py", line 26, in <module>
import socket
File "socket.py", line 5, in <module>
This module provides socket operations and some related functions.
AttributeError: 'module' object has no attribute 'AF_INET'
The Cloud9 Support people have told me that there's nothing wrong with my platform and that matplotLib might not support being initialized within an environment that only has console access. However I remember using matplotlib in the exact same way on Cloud9 about a year ago.
Could anyone explain to me what exactly this error means and if there is a way to get around it?
It seems this is an older version of matplotlib.
Take a note on commit f4adec7 from Aug 2013 where "import urllib" line has been removed from textpath.py. This change is present as early as in matplotlib v1.4.0.
I am using Windows 7. I have installed Python 3.4 and Metmatplotlib.
I have tried the below code
from pylab import *
plot([1,2,3])
show()
But i am getting the follwoign error
Traceback (most recent call last):
File "E:/Work/Python/Training/Samples.py", line 1, in <module>
from pylab import *
File "C:\Python34\lib\site-packages\pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "C:\Python34\lib\site-packages\matplotlib\__init__.py", line 169, in <module>
from urllib2 import urlopen
ImportError: No module named 'urllib2'
I have searched for the package urllib2 but not seems to be find it.
Can any one help me
Thanks,
The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.
https://docs.python.org/2/library/urllib2.html
I am trying to call some functions in openopt package for Python from R using the rJython package. I have the NumPy, SciPy, and OpenOpt installed for Python 2.7.4 on my 64 bit windows 7. Importing openopt from Python is OK.
However, when I run the codes:
library(rJython)
rJython <- rJython(modules='openopt')
rJython$exec("from openopt import GLP")
I got errors:
.jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named openopt
Of course I checked the sys.path values for the Python environment:
rJython$exec("import sys")
rJython$exec("pname = sys.path")
jython.get(rJython, "pname")
but I got:
[1] "C:\\Users\\myname\\Documents\\R\\win-library\\2.15\\rJython\\Lib"
[2] "C:\\Users\\myname\\Documents\\R\\win-library\\2.15\\rJython\\jython.jar\\Lib"
[3] "__classpath__"
[4] "__pyclasspath__/"
[5] "openopt"
[6] "C:/Users/myname/Documents/R/win-library/2.15/rJython"
These are absolutely not like the values of sys.path in Python itself. So I extended the sys.path by:
rJython$exec("sys.path.extend(['C:\\Python27\\lib\\site-packages\\openopt-0.45-py2.7.egg'])")
Then it seems that I need to add the numpy to sys.path:
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\__init__.py", line 10, in <module>
from oo import *
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\oo.py", line 4, in <module>
from LP import LP as CLP
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\LP.py", line 1, in <module>
from baseProblem import MatrixProblem
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\baseProblem.py", line 2, in <module>
from numpy import *
ImportError: No module named numpy
I then extended everything in the sys.path list of Python in rJython. But I still get further information:
Erro in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\__init__.py", line 10, in <module>
from oo import *
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\oo.py", line 4, in <module>
from LP import LP as CLP
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\LP.py", line 1, in <module>
from baseProblem import MatrixProblem
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\baseProblem.py", line 2, in <module>
from numpy import *
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 154, in <module>
import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Python27\lib\site-packages
OK. The main question is: it seems like I cannot import a module from the site-packages. I can absolutely import basic modules in Python2.7.4. Any suggestion?
rJython is a package that does not call Python but Jython, which is not exactly the same thing. In particular, Jython programs cannot currently use CPython extension modules written in C, only those in pure Python.
This is why neither NumPy nor SciPy can be invoked via rJython.
However, rPython, a package with exactly the same interface as rJython does interact with the true Python. You should try that.
There is a caveat, though: it currently only runs on UNIX (Linux/Mac/...) environments, not on Windows. It is possible to have it installed on Windows and there are some instructions as to install it on such platform, but involves some manual configuration of scripts (essentially, to indicate which version of Python is to be used and the path where it is located) and compilation.
I was working with python and matplotlib but my script crashed so I had to turn off the terminal (Ubuntu 12.04, matplotib-1.1.0, python2.7).
Now if I try to run any script it crashes on the line
import matplotlib.pyplot as plt
with the following error
Traceback (most recent call last):
File "new.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/rcsetup.py", line 20, in <module>
from matplotlib.colors import is_color_like
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/colors.py", line 54, in <module>
import matplotlib.cbook as cbook
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/cbook.py", line 32, in <module>
import new
File "/home/federico/Documents/doc_uni/idraulica_ambientale/relazione/scripts/variabili/new.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-i686.egg/matplotlib/pyplot.py", line 23, in <module>
from matplotlib import _pylab_helpers, interactive
ImportError: cannot import name interactive
Notice the last line.
I tried removing and reinstalling matplotlib both from source and from pip and easy_install but I can't get away with it. Same error happens if I try to import from within the python interpreter.
I also installed version 1.2.0 to see if that work but it does not.
If you read through files in the stack trace,
new.py-> /matplotlib/__init__.py -> matplotlib/rcsetup.py, /matplotlib/colors.py -> /matplotlib/cbook.py --> /home/federico/Documents/../new.py -> matplotlib/pyplot.py
You have named your module new which is shadowing with an import in matplolib.cbook, which is causing you to try to imort pyplot while you are importing pyplot which aparently blows up (exactly why is above my paygrade). You just need to re-name your module to something other than new.py (and remember to remove the new.pyc file that got created).
As a test run import matplotlib.pyplot as plt in an interactive shell.
FYI this is what you are shadowing.
This import will be removed in mpl 1.3