SpacePy: "ImportError: cannot import name irbempylib" - python

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!)

Related

ModuleError: No module named pptx found

I am writing a python code for merging ppts. It takes the location of the 2 ppts, merges them and puts the merged ppt formed in the folder given by user. The code used is:
import sys
from pptx import Presentation
#import Aspose.Words.License
#import aspose.slides as a_slides
#import os
#import win32com.client
def merge_powerpoint_ppts(pres_loc1, pres_loc2, output_loc):
p1 = open(pres_loc1)
pres1 = Presentation(p1)
p2 = open(pres_loc2)
pres2 = Presentation(p2)
for slide in pres2.slides:
for lide in pres1.slides:
if slide.shape.title.text == lide.shape.title.text:
pres1.slides.add_Clone(slide)
pres1.save(output_loc)
p1.close()
p2.close()
When I try to debug the code, I get the following:
[Error][1]
[1]: https://i.stack.imgur.com/yID2l.png
I have already installed the module pptx on my system and it is updated, but I am still getting this error.
First if you have a folder named Presentation or pptx change it cause this could happen because of naming confusion of files or folder and python modules
Secondly make sure you use the correct python interpreter or env where you install pptx in in
last Option uninstall pptx and write the following command
conda install -c conda-forge python-pptx

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

Python module script.vis install

Really sorry for my novice question.
I am trying to install a module in python for neo4j but I got an error.
here is the import :
from scripts.vis import vis_network
from scripts.vis import draw
Here is the error:
ModuleNotFoundError: No module named 'scripts'
I have tried "pip install scripts"
Thanks in advance
ModuleNotFoundError simply means the Python interpreter couldn't find the module. I suggest that you read about python modules and packaging here.
I have looked at the source code you pointed to and it works perfectly fine. I suspect your paths are not well set up.
Make sure that in you are running importing scripts.vis in app.py, the directory structure looks like this:
./scripts
./scripts/__init__.py
./scripts/vis.py
....
./app.py #in app.py, you can import as 'from scripts.vis import x'
Here's what it looks on my system:
app.py is successfully able to make the import from vis sub-module. You can use a IPython notebook, that should work fine too.
If you want to visualize the graph in the python environment (Jupyter), you can try using neo4jupyter library. Here you will use neo4jupyter.draw to visualize the graph.
Install !pip install neo4jupyter
For example:
import neo4jupyter
neo4jupyter.init_notebook_mode()
from py2neo import Node
nicole = Node("Person", name="Nicole", age=24)
drew = Node("Person", name="Drew", age=20)
graph.create(nicole | drew)
options = {"Person": "name"}
neo4jupyter.draw(graph, options)
You may find this useful:
https://github.com/merqurio/neo4jupyter
https://nicolewhite.github.io/neo4j-jupyter/hello-world.html

osx - Mac - Python 3.5 - ImportError: No module named 'cubicspline' when testing python package

I recently downloaded a package and when testing the package to see if everything works correctly I get the error ImportError: No module named 'cubicspline'. When following the trail to see where is error occurs I found that cubicspline.py (the file not being found) is in the same folder as extcurve_s16.py (the file calling cubicspline).
File "/Users/Austin/anaconda/lib/python3.5/site-packages/isochrones/schlafly/extcurve_s16.py", line 4, in <module>
import cubicspline
I've checked the permissions on the folder and I'm able to both read and write. There is also an __init__.py file in the folder. Any ideas here? I can't figure out why it wouldn't be able to call a file that is in the same folder. Here is the exact chunk of code for reference, as can be seen import numpy works fine.
import numpy
import cubicspline
The issue was resolved by cloning the isochrones package from Github instead of using pip install isochrones. There was some type of issue with the pip version.

Python Shapely Install Not working?

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

Categories