Plot map No module named 'dbflib' - shapefile

from pylab import *
import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.collections import LineCollection
from mpl_toolkits.basemap import Basemap,cm
import shapefile
import dbflib
import dbflib
Traceback (most recent call last):
File "<ipython-input-398-b5a771049653>", line 1, in <module>
import dbflib
ModuleNotFoundError: No module named 'dbflib'
Tried solutions suggested by other posts like install/uninstall tookit, doesn't work. Anyone has this kind issue?

Related

ModuleNotFoundError: No module named 'core'

Django Version: 3.1.5
folder structure
So, I'm studying Django. When I try to generate random data for my project I get this error:
Traceback (most recent call last):
File "C:\PythonProjects\DJANGO\myblogsite\blog\management\commands\create_data.py", line 2, in <module>
from core.models import Category, Post, Comment
ModuleNotFoundError: No module named 'core'
Process finished with exit code 1
create_data.py
from django.core.management.base import BaseCommand
from core.models import Category, Post, Comment
from random import randint
import datetime
Has anybody a clue how to deal with this problem?
from django.core.management.base import BaseCommand
from blog.models import Category, Post, Comment
from random import randint
import datetime

Python 2.7 NameError: name 'ax1' is not defined

I have Python 2.7 Win 32 and have installed Matplotlib, Numpy, PyParsing, Dateutil. In IDLE I place in the following code:
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np
def graphRawFX () :
date=mdates.strpdate2num('%Y%m%d%H%M%S')
bid, ask = np.loadtxt('GPBUSD1d.txt', unpack=True)
delimiter=',',
converters={0:mdates.strpdate2num('%Y%m%d%H%M%S') }
fig = plt.figure(figsize=(10,7))
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
ax1.plot(date,bid)
ax1.plot(date,ask)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
plt.grid(True)
plt.show()
Running the code results in to the following:
Traceback (most recent call last):
File "C:/Users/Emanuel/Desktop/test.py", line 18, in <module>
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
NameError: name 'ax1' is not defined
Any suggestion to editing the code would be helpful.
This is because you are calling ax1 outside the method in which it has been defined it. Perhaps you should include that line in the method as well.
or else:
You can create the ax1 object outside the method and then change some of its attributes as necessary in your function by using global ax1
EDIT: It should look something like this:
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
def graphRawFX (axes1) :
date=mdates.strpdate2num('%Y%m%d%H%M%S')
bid, ask = np.loadtxt('GPBUSD1d.txt', unpack=True)
delimiter=',',
converters={0:mdates.strpdate2num('%Y%m%d%H%M%S') }
fig = plt.figure(figsize=(10,7))
axes1.plot(date,bid)
axes1.plot(date,ask)
graphRawFX(ax1)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
plt.grid(True)
plt.show()

Cannot use scipy.stats

I get an errr when using scipy.stats. in a script after importing scipy.
AttributeError: 'module' object has no attribute 'stats'
Within script editor I can click on stats after typing scipy. from the pulldown menu,
within python console I can not select python.stats from the pulldown menu, it's not there.
I'm using pandas 2.7 and SciPy 0.13.0
Why is that?
Any known issues?
expanding on my comment (to have a listed answer).
Scipy, as many other large packages, doesn't import all modules automatically. If we want to use the subpackages of scipy, then we need to import them directly.
However, some scipy subpackages load other scipy subpackages, so for example importing scipy.stats also imports a large number of the other packages. But I never rely on this to have the subpackage available in the namespace.
In many packages that use scipy, the preferred pattern is to import the subpackages to have them available by their names, for example:
>>> from scipy import stats, optimize, interpolate
>>> import scipy
>>> scipy.stats
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'stats'
>>> scipy.optimize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'optimize'
>>> import scipy.stats
>>> scipy.optimize
<module 'scipy.optimize' from 'C:\Python26\lib\site-packages\scipy\optimize\__init__.pyc'>
This is expected. Most of the subpackages are not imported when you just do import scipy. There are a lot of them, with a lot of heavy extension modules that take time to load. You should always explicitly import the subpackages that you want to use.
https://github.com/scipy/scipy/issues/13618
if you import scipy alone like this:
import scipy
then you use:
scipy.stats
You will get:
AttributeError: module 'scipy' has no attribute 'stats'
You have to import like this:
import scipy.stats
or
import scipy
import stats

scrapy-linkedin for LinkedIn data extraction

I'm using scrapy-0.16 for data extraction from LinkedIn.
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.http import Request
from scrapy import log
from linkedin.items import LinkedinItem, PersonProfileItem
from os import path
from linkedin.parser.HtmlParser import HtmlParser
import os
import urllib
from bs4 import UnicodeDammit
from linkedin.db import MongoDBClient
https://github.com/pondering/scrapy-linkedin
The error comes
Traceback (most recent call last):
File "C:\Users\TAWANE DUDEZ\Desktop\linkedin\linkedin\spiders\LinkedinSpider.py", line 6, in <module>
from linkedin.items import LinkedinItem, PersonProfileItem
ImportError: No module named linkedin.items
Cannot find linkedin.items module.
My suspicion is that you're trying to run the scrapy crawl LinkedinSpider command from the wrong directory. Try navigating to C:\Users\TAWANE DUDEZ\Desktop\linkedin and then running the command again.
Since the crawler is now starting, you also need to be running a MongoDB instance before starting the crawl. The README of the github project being used says to typemongod to start an instance. Just to check, you do have MongoDB and pymongo installed right?

AttributeError: 'module' object has no attribute 'Unpickler'

I am running a program in the SciTE text editor and it gets stuck at the import scipy as sp statement.
import pylab as pl
import numpy as np
import scipy as sp
import scipy.integrate as spi
import scipy.optimize as spo
import numpy.random as nr
import matplotlib.pyplot as plt
print "check"
#parameters to be used
rs=0.14
ra=0.0027
js=-0.033
ja=0.81
Mz=91.0
Tz=2.5
root_s=sp.linspace(20.,140.,200) #plotting sigma_A and sigma_S functions against centre of mass energies from 20GeV to 140 GeV
s=(root_s)**2
.....
.....
and I get this error message:
>pythonw -u "collisions.py"
3.14159265359
1.0
Traceback (most recent call last):
File "collisions.py", line 4, in <module>
import scipy as sp
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 85, in <module>
from numpy import oldnumeric
File "C:\Python27\lib\site-packages\numpy\oldnumeric\__init__.py", line 14, in <module>
from compat import *
File "C:\Python27\lib\site-packages\numpy\oldnumeric\compat.py", line 106, in <module>
class Unpickler(pickle.Unpickler):
AttributeError: 'module' object has no attribute 'Unpickler'
>Exit code: 1
The odd thing is that my code works perfectly fine in the interactive qtconsole. I am new to programming, and I have not encountered such a problem elsewhere in the internet. And why is it that the values pi and 1.0 are returned even though there is no where in my code that is supposed to do that?