dispersion_plot not working inspite of installing matplotlib - python-2.7

i have installed matplotlib using pip in ubuntu 14.04 LTS.. but on running dispersion_plot this is showing the following error ..
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/text.py", line 455, in dispersion_plot
from nltk.draw import dispersion_plot
ImportError: cannot import name dispersion_plot
I am new to python... can anyone suggest if there is a better way of installing matplotlib in nltk.

The examples of the online book are not quite right.
You may try this:
from nltk.draw.dispersion import dispersion_plot
words = ['Elinor', 'Marianne', 'Edward', 'Willoughby']
dispersion_plot(gutenberg.words('austen-sense.txt'), words)
You may also call it from a text directly:
from nltk.book import text1
from nltk.draw.dispersion import dispersion_plot
dispersion_plot(text1, ['monstrous'])
this way you import the function directly instead of calling the funcion from text object.
I realized this watching at the source code directly.
Hope this work for you

After importing it using spyder, this is how the plot would look.

Related

Why xlsxwriter module does not work like other modules?

Traceback (most recent call last):
File "F:TC.py", line 1, in <module>
import xlsxwriter
ImportError: No module named xlsxwriter
I am getting this error even after trying every possible answer given to this problem earlier.
I am using python 2.7 in windows
I have installed xlsxwriter using pip
I have tried reinstalling python shell but it doesn't work.

from . import nonlinearities cannot import name nonlinearities

there is some really strange problem.
Traceback (most recent call last):
File "mnist.py", line 17, in
import lasagne.nonlinearities as nonlinearities
File "/usr/local/lib/python2.7/dist-packages/lasagne/init.py", line 17, in
from . import nonlinearities
ImportError: cannot import name nonlinearities
As I go to this folder, I find there is it(the name).but for some unkown reason,(I guess path problem). It does not work.
this may be raised by my mistaking operation, but my mistaking command was not executed.
in detail,originally,my lasagne==0.1.and there is some module can not import..so i solved it by installing the leasted version lasagne==0.2.dev1...then it works.for some reason ,i break my program.before i run it again,i had done some unexecuted mistaking command,now the error is there as you see.i guess it because of two version of lasagne under the path /usr/local/lib/python2.7/dist-packages/..so i uninstall all of them,then i reinstall the one version.but the error is still there..
additional..the following command is ok
python
import lasagne
import lasagne.nonlinearites as nonl
this can be solved by first import lasagne then import theano..
if exchange the import order,then the error arise...
this is very strange.i am not sure what happens,but it does work

How can I import the csvsql to Python 2.7

I have successfuly installed csvkit using conda install ...
However, when I try to import the libraries in Python 2.7 Spyder, I get error messages:
import csvsql
Traceback (most recent call last):
File "<ipython-input-5-303a60a6b1ac>", line 1, in <module>
import csvsql
ImportError: No module named csvsql
import csvkit
Traceback (most recent call last):
File "<ipython-input-7-ca8a99ae9834>", line 1, in <module>
import csvkit
ImportError: No module named csvkit
I looked at the documentation -- they describe the installation process but not how the library is loaded in Python.
Moreover, I had an analogous problem with httplib2. I installed it successfuly but when I tried to import it in Spyder I received an analogous error message (No module named httplib2).
(I use Anaconda 3 and Spyder on Windows 11)
Any ideas? Thank you in advance.
I asked this question on the csvkit GitHub / issues forum.
The answer given was: You should use agate on which csvkit now relies for all its operations. See https://github.com/wireservice/agate.
I'm with you -- it would be wonderful to use csvkit as a command-line tool and a library, but it's authors don't see it that way. The full issue: https://github.com/wireservice/csvkit/issues/670

How to Display a Geotiff image using Python

I am new to Python2.7 and have tried installing rasterio,using wheel file,but still the following error comes:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import rasterio
File "D:\Python\lib\site-packages\rasterio\__init__.py", line 23, in <module>
from rasterio._base import (
ImportError: DLL load failed: The specified module could not be found.
I accidentally deleted my old comment,here is the code :
from osgeo import gdal
import matplotlib.pyplot as plt
ds = gdal.Open('filename.tif').ReadAsArray()
im = plt.imshow(ds)
This will work.
I am not familiar with Rasterio, but if you are looking for some library to do image analysis or just display a geotiff image, you could probably take a look at opencv python library.
Link : OpenCV3
TuiView is an open source PyQt-based lightweight Raster GI. Its available on Windows, Mac and Linux: http://tuiview.org

Pyside Import Error "No Module named Ctypes"

Im pretty new to working with this side of python so pardon me if I'm a bit off kilter.
I am trying to incorporate PySide into Cryengine's Python 2.7.5 Integration; I used PIP to install the Site - Package to Cryengines Python Directory using the pip install PySide.whl -t CRYENGINE/Editor/Python/Lib/Site - Package command through command prompt.
Here is the script I am trying to run in the Python Shell Of CryEngine:
import sys
import site
site.ENABLE_USER_SITE
print site.USER_BASE
site.addsitedir("F:\SteamLibrary\steamapps\common\CRYENGINE\Editor\Python\Lib\site-packages\PySide")
from PySide import QtGui
app = QtGui.QApplication(sys.argv)
wid = QtGui.QWidget()
wid.resize(250, 150)
wid.setWindowTitle('Simple')
wid.show()
sys.exit(app.exec_())
I get the following error in the Python script terminal:
] from PySide import QtGui
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\site-packages\PySide\__init__.py", line 41, in <module>
_setupQtDirectories()
File "C:\Python27\lib\site-packages\PySide\__init__.py", line 9, in _setupQtDirectories
from . import _utils
File "C:\Python27\lib\site-packages\PySide\_utils.py", line 31, in <module>
import ctypes
ImportError: No module named ctypes
I used pip to install the PySide wheel files. So its really weird that I am getting this error. I double checked the files that ctypes uses are there, and in the Python 2.7 installation. And all of them are there. I tested this using Python Shell, and it works great! But for some reason when I run it through CryEngine's python 2.7.5 integration even though the file path is to C:\Python27 where all of those file Ctypes files are!
I am almost sure that I am oversimplifying the problem, but I'm not sure where to start getting this problem solved. I want to get this working so I can build an integration that will work for the whole CryEngine Community. I've looked all over the place for a solution, but am really at the end of my rope here.
Any help would be greatly appreciated!!