Python Shapely Install Not working? - python

any thoughts? I've tried uninstalling Shapely and installing with PIP
I have Anaconda and installed Fiona fine and Shapely seemingly fine.
Simple code:
import fiona
import shapely
dirVar = "C:\\Users\\me\\Desktop\\geocode\\"
with fiona.open(dirVar + "Regions.shp") as fiona_collection:
shapefile_record = fiona_collection.next()
shape = shapely.geometry.asShape(shapefile_record['geometry']) #GET ERROR HERE
point = shapely.geometry.Point(32.398516, -39.754028) # longitude, latitude
if shape.contains(point):
print "Found shape for point."
AttributeError: 'module' object has no attribute 'geometry'
When I look at the methods of shapely from Wing IDE I see only:
ctypes_declarations
ftools
geos
I would think I should see geometry if it was installed correctly?
Any thoughts?

You could use one of these:
import shapely.geometry
or
from shapely import geometry

Related

Can´t import qiskit, attribute error in numpy: " 'numpy.random' has no attribute 'default_rng'"

I´m using Python 3 and I´m working in jupyter, when I try to import qiskit the following error is showed:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-578b7f7e9727> in <module>
----> 1 import qiskit
~\AppData\Roaming\Python\Python36\site-packages\qiskit\quantum_info\synthesis\two_qubit_decompose.py in __init__(self, unitary_matrix)
169 # D, P = la.eig(M2) # this can fail for certain kinds of degeneracy
170 for i in range(100): # FIXME: this randomized algorithm is horrendous
--> 171 state = np.random.default_rng(i)
172 M2real = state.normal()*M2.real + state.normal()*M2.imag
173 _, P = la.eigh(M2real)
AttributeError: module 'numpy.random' has no attribute 'default_rng'
I got almost the same error as:
AttributeError: module 'numpy.random' has no attribute 'default_rng'
with the numpy version of '1.16.2'
numpy.__version__
'1.16.2'
As a solution, either you need to put these lines at the top of your file:
import numpy
numpy.random.bit_generator = numpy.random._bit_generator
Or the your current numpy version probably is <= 1.17. Hence, you need to update the NumPy version. For instance, I have updated it on Anaconda environment as:
conda update numpy
And the current version is:
numpy.__version__
'1.19.2'
Updates take time because of lots of dependencies of NumPy. Hopefully, the issue is resolved on my side!
You need NumPy 1.17 or later to have the new RNG functions that Qiskit needs
if you're using jupyter in anaconda - uninstalling, reinstalling and restarting the kernel worked for me similar here: AttributeError: module 'numpy' has no attribute '__version__'
!pip uninstall -y numpy
!pip install numpy
RESTART KERNEL

AttributeError: module 'sst' has no attribute 'train_reader'

I am very new to sentiment analysis. Trying to use Stanford Sentiment Treebank(sst) and ran into an error.
from nltk.tree import Tree
import os
import sst
trees = "C:\\Users\m\data\trees"
tree, score = next(sst.train_reader(trees))
[Output]:
AttributeError Traceback (most recent call last)
<ipython-input-19-4101f90b0b16> in <module>()
----> 1 tree, score = next(sst.train_reader(trees))
AttributeError: module 'sst' has no attribute 'train_reader'
I think you're looking for https://github.com/JonathanRaiman/pytreebank, not https://pypi.org/project/sst/.
On the python side, that error is pretty clear. Once you import the right package, though, I'm not sure I saw train_reader but I could be wrong.
UPDATE:
I'm not entirely sure why you're running into the 'sst' not having the attribute train_reader. Make sure you didn't accidentally install the 'sst' package if you're using conda. It looks like the 'sst' is referring to a privately created module and that one should work.
I got your import working but what I did was I:
Installed everything specified in the requirements.txt file.
import sst was still giving me an error so I installed nltk and sklearn to resolve that issue. (fyi, im not using conda. im just using pip and virtualenv for my own private package settings. i ran pip install nltk and pip install sklearn)
At this point, import sst worked for me.
I guess you're importing the sst package selenium-simple-test, which is not what you're looking for.
Try sst.discover() , if you get the error
TypeError: discover() missing 4 required positional arguments: 'test_loader', 'package', 'dir_path', and 'names'
You are using the selenium-simple-test package

RuntimeError: b'no arguments in initialization list'

I'm trying to solve my issue in my own but I couldn't, I'm trying to run this code in every format you can imagine and in ArcGIS pro software it's the same I can't find this error message in any other issue. From similar issues, it seems some data files could be missing?
import geopandas as gpd
import json
import numpy as np
from shapely.geometry import LineString, Point, box
import ast
from pyproj import Proj
paths = road_features.SHAPE.map(lambda x: np.array(ast.literal_eval(x)["paths"][0]))
pathLineStrings = paths.map(LineString)
gdf = gpd.GeoDataFrame(road_features,geometry=pathLineStrings)
#gdf.crs = {'init': 'epsg:3857'}
gdf.crs = {'init': 'epsg:4326'}
gdf = gdf.to_crs({'init': 'epsg:4326'})
i get this error
RuntimeError: b'no arguments in initialization list'
also i tried it in arcgis pro i got the same
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\geopandas\geodataframe.py", line 443, in to_crs
geom = df.geometry.to_crs(crs=crs, epsg=epsg)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\geopandas\geoseries.py", line 304, in to_crs
proj_in = pyproj.Proj(self.crs, preserve_units=True)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\pyproj\__init__.py", line 362, in __new__
return _proj.Proj.__new__(self, projstring)
File "_proj.pyx", line 129, in _proj.Proj.__cinit__
RuntimeError: b'no arguments in initialization list'
to make sure this is pyproj error rather than geopandas.
import pyproj
pyproj.Proj("+init=epsg:4326")
if the above runtime error is the same, we can be sure this error is due to pyproj.
just conda remove pyproj and install it with pip.
pip install pyproj
at least this works for me.
Today(July 30), I resintalled from miniconda, conda remove pyproj did not work for me, instead I pip uninstall pyproj and pip install pyproj makes everything fine.
The problem is problably within the pyproj instalation of Anaconda on Windows platform. Just like Stephen said, solution is to edit the path in "datadir.py" (located in ...Anaconda3\Lib\site-packages\pyproj).
Correct path is ".../Anaconda3/Library/share". Make sure full path is complete (may contain username etc.). I also needed to change \ to /.
This change worked for me. Yes and after this change, it is necesary to restart Spyder (or whatever you use).
Is there an initial crs defined?
I ran into the same problem only when I passed only the epsg command: gdf.to_crs('epsg:4326').
As you show
my_geoseries.crs = {'init' :'epsg:3857'}
should be the first step and then transforming to
gdf = gdf.to_crs({'init': 'epsg:4326'})
If you are working in ArcGIS you could also check in the properties whether the initial epsg is defined ?
I'm using Pycharm.
I had to use a combination of both Stone Shi's remark and Dorregaray's.
import pyproj
pyproj.Proj("+init=epsg:4326")
> RuntimeError: b'no arguments in initialization list'
According to Stone Shi, the above proves that it's a pyproj err.
So I used Pycharm->Settings and reinstalled pyproj.
Then
import pyproj
pyproj.Proj("+init=epsg:4326")
> RuntimeError: b'no arguments in initialization list'
So, it's a pyproj err but Pycharm->Settings reinstalling pyproj does not help me.
I then edited my C:\Anaconda3\Lib\site-packages\pyproj\datadir.py
from:
pyproj_datadir="C:/Anaconda3\share\proj"
to Dorregaray's:
pyproj_datadir="C:\Anaconda3\Library\share"
Then test again:
import pyproj
pyproj.Proj("+init=epsg:4326")
>Process finished with exit code 0
No Runtime Error!
Then test on my
wgs84 = data.to_crs({'init': 'epsg:4269'})
>Process finished with exit code 0
For me upgrading pyproj and geopandas, fixed this issue:
pip install pyproj --upgrade
pip install geopandas --upgrade
Using Geopandas, try that (it should work) :
gdf = gpd.GeoDataFrame(gdf, geometry=gdf['geometry'])
gdf.crs = {'init' :'epsg:2154'}
gdf = gdf.to_crs({'init' :'epsg:4326'})
You should redefine well your geodataframe,
then define the initial geo referential
and finally convert it in the good one.
Don't forget to drop the NaN if there are any.
I came across the same error. I was working with Python version 3.6.3 and Geopandas version 0.4.0. It was solved by using the following instead of df = df.to_crs({'init': 'epsg:4326'}):
df = df.to_crs(epsg=4326)
you can force reinstall pyproj from pip directly using
pip install --upgrade --force-reinstall pyproj
instead of uninstalling and reinstall again which will also uninstall all the dependent libraries

h5py not installing properly on canopy?

I programme in python and I use a OS X Yosemite version 10.10.2. I have installed h5py 2.5.0-1 in enthought canopy using its package manager. So, h5py 2.5.0-1 has appeared in my installed packages in canopy with a little green tick besides it.
However, when I test it, using the code below or any other code related to h5py, it gives me an error:
This is my test code:
import h5py
import numpy as np
f = h5py.File('test.hdf5', 'w')
This is the error:
1 import h5py
2 import numpy as np
----> 3 f = h5py.File('test.hdf5', 'w')
4
5
AttributeError: 'module' object has no attribute 'File'
As an additional information, my numpy package works properly.Could anybody help me with that please? Thank you very much in advance!

SpacePy: "ImportError: cannot import name irbempylib"

I downloaded spacepy via easy_install.exe in the command prompt and this code doesn't raise an error:
import spacepy.coordinates as coord
from spacepy.time import Ticktock
import numpy as np
def geotomag(alt,lat,lon):
#call with altitude in kilometers and lat/lon in degrees
Re=6371.0 #mean Earth radius in kilometers
#setup the geographic coordinate object with altitude in earth radii
cvals = coord.Coords([np.float((alt/Re+Re))/Re,np.float(lat),np.float(lon)], 'GEO', 'sph',['Re','deg','deg'])
#set time epoch for coordinates:
cvals.ticks=Ticktock(['2012-01-01T12:00:00'], 'ISO')
#return the magnetic coords in the same units as the geographic:
return cvals.convert('MAG','sph')
When I try to call the function, however, it gives me "ImportError: cannot import name irbempylib".
Irbempylib is supposed to be included in spacepy as evidenced by the help doc:
PACKAGE CONTENTS
LANLstar
coordinates
data_assimilation
datamodel
empiricals
irbempy (package)
lib
omni
plot (package)
poppy
pybats (package)
pycdf (package)
radbelt
rst
seapy
spacepy_EnKF
time
toolbox (package)
Any ideas?
I also had had this problem. I think it is to do with the missing source files for irbempylib with a particuar version of SpacePy.
To fix this I deleted all references to SpacePy (files and folder(s)) from the "site-packages" folder of your Python installation. Then did a fresh install of SpacePy using Pip: pip install spacepy. This downloaded and installed SpacePy version 0.1.5.
Re-run your Python code and it should work (it did for me!)

Categories