'Polygone' object does not support indexing - python-2.7

I am trying to render an SVG map using Kartograph.py. It throws me the TypeError. Here is the python code:
import kartograph
from kartograph import Kartograph
import sys
from kartograph.options import read_map_config
css = open("stylesheet.css").read()
K = Kartograph()
cfg = read_map_config(open("config.json"))
K.generate(cfg, outfile='dd.svg', format='svg', stylesheet=css)
Here is the error it throws
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
K.generate(cfg, outfile='dd.svg', format='svg', stylesheet=css)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\kartograph.py", line 46, in generate
_map = Map(opts, self.layerCache, format=format)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\map.py", line 61, in __init__
layer.get_features()
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\maplayer.py", line 81, in get_features
charset=layer.options['charset']
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 121, in get_features
geom = shape2geometry(shp, ignore_holes=ignore_holes, min_area=min_area, bbox=bbox, proj=self.proj)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 153, in shape2geometry
geom = shape2polygon(shp, ignore_holes=ignore_holes, min_area=min_area, proj=proj)
File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 217, in shape2polygon
poly = MultiPolygon(polygons)
File "C:\Python27\lib\site-packages\shapely\geometry\multipolygon.py", line 74, in __init__
self._geom, self._ndim = geos_multipolygon_from_polygons(polygons)
File "C:\Python27\lib\site-packages\shapely\geometry\multipolygon.py", line 30, in geos_multipolygon_from_polygons
N = len(ob[0][0][0])
TypeError: 'Polygon' object does not support indexing

I had a look at shapely and it seems like you are using an outdated version.
Update your current install:
pip install -U shapely

Related

Failed to run pytest with allure on my docker image,"invalid syntax"

I try to run pytest with allure on my docker image, but it reports an "invalid syntax" error. Is there any python version requirement for allure? The python version on my docker image is 2.7.13.
Can anyone help me?
root#ubuntu:/fuego-rw/buildzone# pytest allure_title.py
Traceback (most recent call last):
File "/usr/local/bin/pytest", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 65, in main
config = _prepareconfig(args, plugins)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 214, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "/usr/local/lib/python2.7/dist-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/usr/local/lib/python2.7/dist-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/pluggy/manager.py", line 87, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/usr/local/lib/python2.7/dist-packages/pluggy/callers.py", line 203, in _multicall
gen.send(outcome)
File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 94, in pytest_cmdline_parse
config = outcome.get_result()
File "/usr/local/lib/python2.7/dist-packages/pluggy/callers.py", line 81, in get_result
_reraise(*ex) # noqa
File "/usr/local/lib/python2.7/dist-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 789, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 997, in parse
self._preparse(args, addopts=addopts)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 943, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "/usr/local/lib/python2.7/dist-packages/pluggy/manager.py", line 299, in load_setuptools_entrypoints
plugin = ep.load()
File "/usr/local/lib/python2.7/dist-packages/importlib_metadata/__init__.py", line 105, in load
module = import_module(match.group('module'))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/_pytest/assertion/rewrite.py", line 304, in load_module
exec(co, mod.__dict__)
File "/usr/local/lib/python2.7/dist-packages/allure_pytest/plugin.py", line 3, in <module>
import allure
File "/usr/local/lib/python2.7/dist-packages/allure.py", line 1, in <module>
from allure_commons._allure import title
File "/usr/local/lib/python2.7/dist-packages/allure_commons/__init__.py", line 3, in <module>
from allure_commons._allure import fixture # noqa: F401
File "/usr/local/lib/python2.7/dist-packages/allure_commons/_allure.py", line 165
def __call__(self, func: _TFunc) -> _TFunc:
^
SyntaxError: invalid syntax
This syntax:
func: _TFunc
is called a type hint, meaning the variable func is expected to be of type _TFunc (in simpler terms, num: int means the variable num is expected to be int).
The type hint feature was only made available from Python3.0 (PEP 3107) and Python3.5 (PEP 484), thus isn't available in the version you are using which is Python2.7.
def func(num: int):
print(num)
func(1)
Using Python2
File "Main.py", line 1
def func(num: int):
^
SyntaxError: invalid syntax
Using Python3
1
Either upgrade your Python version to >=3.5 or use an older version of allure-pytest. I would advise to upgrade Python as that would be more sustainable.

How to load .mrc file in python?

I am trying to load a .mrc file in python. But, I am getting error.
Code(ReadMrcTest.py)::
import numpy as np
import h5py
imgPath = 'usr/Task1/emd-62.mrc' #Even for 'usr/task1/emd-62.mrc', same error
image = h5py.File(imgPath)
print image
Error:
Traceback (most recent call last):
File "ReadMrcTest.py", line 8, in <module>
image = h5py.File(imgPath)
File "/usr/s029/.local/lib/python2.7/site-packages/h5py/_hl/files.py", line 271, in __init__
fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
File "/usr/s029/.local/lib/python2.7/site-packages/h5py/_hl/files.py", line 126, in make_fid
fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip-nCYoKW-build/h5py/_objects.c:2840)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip-nCYoKW-build/h5py/_objects.c:2798)
File "h5py/h5f.pyx", line 98, in h5py.h5f.create (/tmp/pip-nCYoKW-build/h5py/h5f.c:2284)
**IOError: Unable to create file (Unable to open file: name = '/usr/task1/emd-62.mrc', errno = 17, error message = 'file exists', flags = 15, o_flags = c2)**
Thanks in advance

python - error with pyttsx

When I run this code that is straight from the website
import pyttsx
engine = pyttsx.init()
engine.say('Greetings!')
engine.say('How are you today?')
engine.runAndWait()
I get this error :
Traceback (most recent call last):
File "C:\Users\Aymen\Desktop\AI.py", line 2, in <module>
engine = pyttsx.init()
File "C:\Python27\lib\site-packages\pyttsx\__init__.py", line 39, in init
eng = Engine(driverName, debug)
File "C:\Python27\lib\site-packages\pyttsx\engine.py", line 45, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Python27\lib\site-packages\pyttsx\driver.py", line 66, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 37, in buildDriver
return SAPI5Driver(proxy)
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 56, in __init__
self.setProperty('voice', self.getProperty('voice'))
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 87, in getProperty
return self._tts.Voice.Id
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 466, in __getattr__
return self._ApplyTypes_(*args)
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 459, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147221164), None)
im on windows 10 using python 2.7
install pywin32 then make sure that pywintypes27.dll is in the C:\Windows\System32 directory.
If you are using python3 , use the pyttsx3 library instead of pyttsx.
pip install pyttsx3
It has no errors as far as i have tested.

Python error: function does not return a valid float

def voigt_PD(x,y0,xc,A,wG,wL):
def integconvo(t,x1,xc1,wG1,wL1):
return exp(-t**2)/((sqrt(log(2))*wL1/wG1)**2+ ((sqrt(4*log(2))*(x1- xc1)/wG1)-t)**2)
return y0+(A*(2*log(2)/pi**1.5)*(wL/wG**2)* quad(integconvo,-inf,inf,args=(x,xc,wG,wL)))
I am defining this voigt model function to fit a curve but I am getting an error stating that "Supplied function does not return a valid float". The following is the fitting routine and followed by the error. Can anyone help to find the mistake ? Thanks in advance
import pylab
from lmfit import Model
from readdatafile import readdatafile
from voigt_PD import voigt_PD
X,Y = readdatafile('data.dat')
gmod = Model(voigt_PD)
result = gmod.fit(Y, x=X,y0=0,xc=0,A=0.1,wG=0.5,wL=0.5)
print(result.fit_report())
pylab.plot(X, Y, 'bo')
pylab.plot(X, result.best_fit, 'r-')
pylab.show()
Then it gives
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "E:/programming/python scripts/test5.py", line 29, in <module>
result = gmod.fit(Y, x=X,y0=0,xc=0,A=0.1,wG=0.5,wL=0.5)
File "build\bdist.win32\egg\lmfit\model.py", line 542, in fit
File "build\bdist.win32\egg\lmfit\model.py", line 746, in fit
File "build\bdist.win32\egg\lmfit\model.py", line 408, in eval
File "voigt_PD.py", line 13, in voigt_PD
return y0+(A*(2*log(2)/pi**1.5)*(wL/wG**2)* (quad(integconvo,-inf,inf,args=(x,xc,wG,wL)))[0])
File "C:\Python27\lib\site-packages\scipy\integrate\quadpack.py", line 311, in quad
points)
File "C:\Python27\lib\site-packages\scipy\integrate\quadpack.py", line 378, in _quad
return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
quadpack.error: Supplied function does not return a valid float.

Python, Networked programs from a book by Dr Charles Severance

I am a beginner in programming, started from Python. I learn by Dr Charles Severance materials. So in his book there is an example:
import urllib
fhand = urllib.urlopen('http://www.py4inf.com/code/rom...
for line in fhand:
print line.strip()
When I copy paste it to Python 2 version (I use PyCharm 5.0.4) there appears:
Traceback (most recent call last):
File "D:/Python4yk/temprehg111.py", line 2, in <module>
fhand = urllib.urlopen('http://www.py4inf.com/code/rom...
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 292, in open_http
import httplib
File "C:\Python27\lib\httplib.py", line 79, in <module>
import mimetools
File "C:\Python27\lib\mimetools.py", line 6, in <module>
import tempfile
File "C:\Python27\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
File "random.py", line 3, in <module>
integers
NameError: name 'line' is not defined
When I type another example, gets an error also. What is wrong? I don`t even write a program. I just copy paste an example. Asked Dr Chuck - still no answer.
Try this:
import urllib
fhand = urllib.urlopen('http://www.py4inf.com')
for line in fhand:
print line.strip() # notice the indentation