Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no arguments in initialization list" runtime error #134

Closed
rgommers opened this issue Jul 3, 2018 · 69 comments
Closed

"no arguments in initialization list" runtime error #134

rgommers opened this issue Jul 3, 2018 · 69 comments

Comments

@rgommers
Copy link

rgommers commented Jul 3, 2018

Hi, I'm running into a cryptic error. My CRS in the geopandas dataframe seems to be properly set, however I cannot convert it to any other CRS.

>>> print(gdf_PLU.crs)
epsg:2193
>>>gdf_PLU.to_crs(epsg=4326)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-92-46b32e6c8012> in <module>()
      1 print(gdf_PLU.crs)
----> 2 gdf_PLU.to_crs(epsg=4326)

~/anaconda3/envs/hthf/lib/python3.6/site-packages/geopandas/geodataframe.py in to_crs(self, crs, epsg, inplace)
    384         else:
    385             df = self.copy()
--> 386         geom = df.geometry.to_crs(crs=crs, epsg=epsg)
    387         df.geometry = geom
    388         df.crs = geom.crs

~/anaconda3/envs/hthf/lib/python3.6/site-packages/geopandas/geoseries.py in to_crs(self, crs, epsg)
    283             except TypeError:
    284                 raise TypeError('Must set either crs or epsg for output.')
--> 285         proj_in = pyproj.Proj(self.crs, preserve_units=True)
    286         proj_out = pyproj.Proj(crs, preserve_units=True)
    287         project = partial(pyproj.transform, proj_in, proj_out)

~/anaconda3/envs/hthf/lib/python3.6/site-packages/pyproj/__init__.py in __new__(self, projparams, preserve_units, **kwargs)
    356         # on case-insensitive filesystems).
    357         projstring = projstring.replace('EPSG','epsg')
--> 358         return _proj.Proj.__new__(self, projstring)
    359 
    360     def __call__(self, *args, **kw):

_proj.pyx in _proj.Proj.__cinit__ (_proj.c:1170)()

RuntimeError: b'no arguments in initialization list'

I can't find this error message in any other issue. From similar issues it seems some data files could be missing (if so, how can I install them; I'm using the binary that is dragged in by conda-forge geopandas). Or is it something else?

@rgommers
Copy link
Author

rgommers commented Jul 5, 2018

A bit of digging found that the data file for all EPSG codes is in site-packages/pyproj/data/epsg. That does contain the code I'm using:

# NZGD2000 / New Zealand Transverse Mercator 2000
<2193> +proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ell      ps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs  <>

So that seems fine. Still unclear what the problem here is.

@ocefpaf
Copy link
Contributor

ocefpaf commented Jul 5, 2018

Can you share the data or a simple example that reproduces the error?

@rgommers
Copy link
Author

rgommers commented Jul 5, 2018

I'll need to dig it out of a larger code base and change to dummy data, but will try that in a few hours.

@micahcochran
Copy link
Collaborator

@rgommers Try this code in the Python console.

>>> from pyproj import Proj
>>> Proj('+init=epsg:2193', preserve_flags=True)

Does it produce an error?

This is what should be passed in that line, please try it, too.

>>> Proj({'init': 'epsg:2193', 'no_defs': True}, preserve_flags=True)

Does that error?

@rgommers
Copy link
Author

rgommers commented Jul 5, 2018

@micahcochran both of those work fine.

@micahcochran
Copy link
Collaborator

@rgommers That's exactly what that line should be doing in Python 3.6.

Unless you are having problems with Fiona (doubtful):

>>> from fiona.crs import from_epsg
>>> from_epsg(2193)
{'init': 'epsg:2193', 'no_defs': True}

@rgommers
Copy link
Author

rgommers commented Jul 5, 2018

Okay here's a standalone example that managed to isolate the problem; with @micahcochran's suggestions things work as expected.

I'd say this is still a valid issue - a clearer error would have allowed finding the problem more easily. If you agree, I can send a PR for that.

import numpy as np
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point


def df_to_gdf(input_df, crs='epsg:2193'):
    """
    Convert a DataFrame with longitude and latitude columns
    to a GeoDataFrame.
    """
    df = input_df.copy()
    geometry = [Point(xy) for xy in zip(df.easting, df.northing)]
    return gpd.GeoDataFrame(df, crs=crs, geometry=geometry)


northing = [6.095531e+06, 5.681031e+06]
easting = [1.675638e+06, 2.020215e+06]
some_data = [1, 2]
df = pd.DataFrame(data=np.asarray([northing, easting, some_data]).T,
                  columns=['northing', 'easting', 'somedata'])
try:
    gdf = df_to_gdf(df)
    gdf.to_crs(epsg=4326)
except RuntimeError:
    print('epsg:2193 didnt work')

gdf = df_to_gdf(df, crs='+init=epsg:2193')
gdf2 = gdf.to_crs(epsg=4326)
print(gdf2.crs)

gdf = df_to_gdf(df, crs={'init': 'epsg:2193', 'no_defs': True})
gdf3 = gdf.to_crs(epsg=4326)
print(gdf3.crs)

gives

epsg:2193 didnt work
{'init': 'epsg:4326', 'no_defs': True}
{'init': 'epsg:4326', 'no_defs': True}

@micahcochran
Copy link
Collaborator

I'd accept a PR for an improved error message.

@iboates
Copy link
Contributor

iboates commented Oct 19, 2018

I'm encountering this error still and nothing in this thread has helped. I have tried:

p2 = pyproj.Proj("epsg:26910")
p2 = pyproj.Proj(init="epsg:26910")
p2 = pyproj.Proj('+init=epsg:26910', preserve_flags=True)
p2 = pyproj.Proj({'init': 'epsg:26910', 'no_defs': True}, preserve_flags=True)

Every single one of them returns RuntimeError: b'no arguments in initialization list'

Python version is 3.6 and pyproj version is 1.9.5.1, installed with anaconda

@iboates
Copy link
Contributor

iboates commented Oct 19, 2018

I do notice however that @rgommers' folder where he found all the projection definitions (site-packages/pyproj/data/epsg) does not seem to exist for me, instead all I found was a python file called datadir.py with a link to the filepath C:/FILES/boates/Anaconda/envs/cavi-3dscene-generator\share\proj, which does not seem to even exist, no share folder in is in C:/FILES/boates/Anaconda/envs/cavi-3dscene-generator

@iboates
Copy link
Contributor

iboates commented Oct 19, 2018

After a bit of frigging around I was able to figure out the problem. I downloaded the repo source code and copied the folder pyproj-master.zip\pyproj-master\lib\pyproj\data and copied to the location indicated in site-packages/pyproj/data/epsgdatadir.py (making sure the names lined up, I had to rename the folder from data to proj

After that, the library worked perfectly. Perhaps it is a problem with using Anaconda to install it, but this extremely crucial data folder was simply not copied, or was possibly copied to the wrong location.

@Eskapp
Copy link

Eskapp commented Nov 15, 2018

@iboates I'm facing the same issue as you. I copied the data folder into Anaconda's site-packages/pyproj/. However, I'm quite confused about the next step you describe. I do not find any file named epsgdatadir.py. Where can I find this file? I am not able to find it on the repo :/

Update: I solved my issue! Anaconda weirdly did not install the dependencies as it usually does. So after installing Cython, it seems to finally work.

@Jens-R-Pedersen
Copy link

Jens-R-Pedersen commented Nov 21, 2018

I'm also facing the same issue, but comments above by @Eskapp Eskapp make no sense to me. I also use Anaconda. Can you clarify what exactly needs to be done to clear this error?

@Eskapp
Copy link

Eskapp commented Nov 21, 2018

Trying to clarify @Jens-R-Pedersen :
I copied the data folder (located here: https://github.com/jswhit/pyproj/tree/master/lib/pyproj/) in C:\Anaconda3\Lib\site-packages\pyproj\ (which I am not sure is useful or not because after that, the error was still there)

Then, I realized that Cython was not installed in the environment I was working in. So I installed it and after that the error disappeared and everything works perfectly. I would suggest checking that Cython is installed, the first thing to try.

@Jens-R-Pedersen
Copy link

Jens-R-Pedersen commented Nov 21, 2018 via email

@Eskapp
Copy link

Eskapp commented Nov 23, 2018

@Jens-R-Pedersen You can clone the repo or download it as a zip file.

@kaandogusoy
Copy link

I am also having the same problem. Basically, I try to change crs of a dataframe by the following line and it is not been working for the last week: dataframe2 = dataframe1.to_crs(epsg='4326')
It was working about 10 days ago, so I do not know why it is not working now. Any help would be appreciated

@QuLogic
Copy link

QuLogic commented Dec 4, 2018

We seem to be triggering this in the initial Cartopy AppVeyor setup, but only on Python 3.6 and not 2.7. Note that the 2.7 build also pins Cython 0.17 and proj4 4.9.1, among others, and then ends up with pyproj 1.9.4. The 3.6 build uses the latest of everything, ending up with pyproj 1.9.5.1.

@QuLogic
Copy link

QuLogic commented Dec 4, 2018

OK, I actually figured out the issue we were having. We activate the environment and then install everything other than Python in it. But latest proj builds set PROJ_LIB and we need to activate the environment after installing it. Easiest fix was to request all needed packages when creating the environment, and then activate it.

So for anyone else hitting this, make sure you a) are installing in an environment, not the root, and; b) activate after installing proj (or pyproj).

@jfnk
Copy link

jfnk commented Dec 14, 2018

I experienced the same Error (using an anaconda python 3.6 and pyproj 1.9.5.1) and fixed it by manually downloading the data directory as suggested by @Eskapp and then set the PROJ_LIB environment variable to point to the data directory.

This fixed the issue.

Maybe this is due to an error in the conda recipe?

@iboates
Copy link
Contributor

iboates commented Dec 15, 2018

@jfnk: I think so, in my case I was also missing the data directory with an anaconda install, and downloading it manually and sticking it where it was expected to be fixed the issue.

@forkozi
Copy link

forkozi commented Dec 18, 2018

I was having the same issue in a 32-bit miniconda Python 2.7 environment. I did the same thing @jfnk did, and everything worked great. Thanks!

@svilella
Copy link

svilella commented Jan 9, 2019

Hi, I am experiencing the same issue but nothing proposed in this topic helps. I am running Python 3.7.2, without Anaconda, on OsX Mojave. I should have everything installed, the 'data' folder in pyproj is there (I downloaded and overwrote it again just to be sure).

I find really strange that the same code, on my old laptop (same kind of Python installation, without conda) and on the very same files, worked flawlessly. Now it's not working, it returns this error when I try to set the crs, but I really don't understand what's the matter here.

@irfanghani86
Copy link

Hi, I am experiencing the same issue but nothing proposed in this topic helps. I am running Python 3.7.2, without Anaconda, on OsX Mojave. I should have everything installed, the 'data' folder in pyproj is there (I downloaded and overwrote it again just to be sure).

I find really strange that the same code, on my old laptop (same kind of Python installation, without conda) and on the very same files, worked flawlessly. Now it's not working, it returns this error when I try to set the crs, but I really don't understand what's the matter here.

Installing the latest version of cython would help

@geo-py
Copy link

geo-py commented Jan 29, 2019

Hello Guys. I'm really new to Python and am running into the same error. I've been trying to work through this introductory course to Python for remote sensing purposes

https://github.com/patrickcgray/open-geo-tutorial

I get the issue in the following Jupyter notebook:

chapter_4_vector.ipynb

I get the following runtime error:

RuntimeError: b'no arguments in initialization list'

Would anyone be willing to walk me through?

@hahakid
Copy link

hahakid commented Jan 30, 2019

Hi, guys.
I meet the problem on Win7 and anaconda. My code run well on ubuntu, but get the above problem.
I have a simple solution, just uninstall the pyproj from anaconda and use pip install instead.
It works on my win7.

@ibrahimhersi3
Copy link

hey guys !

thank you so much for the help and suggestions.
i had the same exact problem as @rgommers after following @Eskapp and @iboates steps everything seem to work fine. I will briefly explain what i did for those who are still facing problems.

  1. I downloaded the whole pyproj folder from (https://github.com/jswhit/pyproj/tree/master/lib/) and replaced that with my old pyproj folder in my directory (C:\Anaconda3\Lib\site-packages)
  2. Try to run your code (hope it works !)
  3. If step 2 is not working then try pip installing Cython by going to terminal and type in "pip install Cython"

@snowman2
Copy link
Member

snowman2 commented Jul 6, 2019

Can you provide this information:

- pyproj version (`python -c "import pyproj; print(pyproj.__version__)"`)
 - PROJ version (`python -c "import pyproj; print(pyproj.proj_version_str)"`)
 - Python version (`python -c "import sys; print(sys.version.replace('\n', ' '))"`)
 - Operation System Information (`python -c "import platform; print(platform.platform())"`)

@snowman2
Copy link
Member

snowman2 commented Jul 6, 2019

Also, I haven't seen preserve_flags before. Do you mean preserve_units?

@jessedhenderson
Copy link

Thanks a lot for all the helpful comments ! The solution of @rickantonais worked for me too:

1. no additional download necessary, but introduce the following code:
2. import os
3. os.environ['PROJ_LIB']=r"C:[... _path to_ ….]\Anaconda3\Library\share"  

This solution worked for me as well. Installed pyproj with conda. Windows 7.

@prasunkgupta
Copy link

It was working till yesterday. Today I booted up my system, started the notebook and now it is not working :(

@snowman2

- pyproj version (`python -c "import pyproj; print(pyproj.__version__)"`)
 - PROJ version (`python -c "import pyproj; print(pyproj.proj_version_str)"`)
 - Python version (`python -c "import sys; print(sys.version.replace('\n', ' '))"`)
 - Operation System Information (`python -c "import platform; print(platform.platform())"`)

1.9.6
0.5.20
3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
Windows-10-10.0.17763-SP0

@jessedhenderson - This does not work for me.

1. no additional download necessary, but introduce the following code:
2. import os
3. os.environ['PROJ_LIB']=r"C:[... _path to_ ….]\Anaconda3\Library\share"  

@prasunkgupta
Copy link

@snowman2

Can y'all try pyproj==2.1.0 and see if it resolved this issue. You can install it with:
pip install pyproj==2.1.0 to use binary wheels
or with:
conda install -c conda-forge pyproj=2.1.0

gives:

(geo_env) C:\>conda install -c conda-forge pyproj=2.1.0
Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - gdal
  - pyproj=2.1.0
Use "conda info <package>" to see the dependencies for each package.

@prasunkgupta
Copy link

This will definitely churn some stomachs.
Case1: Open the jupyter notebook with correponding environment (geo_env) directly and call the method to_crs --- Error "RuntimeError: b'no arguments in initialization list'"
image

Case2: I open anaconda prompt, activate my environment (geo_env), start my jupyter notebook and call the method to_crs --- No Errors!!!
image

@AlexandraKapp
Copy link

so I had the same problem. Using conda uninstall pyproj and then pip install pyproj worked to run the code

from pyproj import Proj
Proj('+init=epsg:2193', preserve_flags=True)

With pip version 2.2.1 is installed, so that workes, but conda uses Version 1.9.6.

But once I installed geopandas, conda would install pyproj with Version 1.9.6 again and then my code would also crashed again.

It worked, once I manually deleted the pyproj folder in anaconda\Lib\site-packages instead of using conda uninstall. And then use pip install pyproj.

@calbaker
Copy link

calbaker commented Aug 5, 2019

I have this same problem in a Jupyter Notebook, but it works fine in Visual Studio Code. Any ideas as to how this could be?

@AlexandraKapp
Copy link

Maybe your running the code in a different env in the jupyter notebook?

@calbaker
Copy link

calbaker commented Aug 7, 2019

I have only the one base environment. What's also weird is that if I export the python script from VSCode as a Jupyter Notebook, VSCode launches the Jupyter Notebook, and the Jupyter Notebook works! This is not, however, a great solution as it involves extra steps.

@calbaker
Copy link

calbaker commented Aug 7, 2019

Interestingly, if I launch either JupyterLab or Jupyter Notebook from Anaconda Navigator, rather than from an Anaconda Powershell Prompt, I get no errors! Shouldn't these all be the same?

@smcateer
Copy link

I encountered this error when I tried to run:

from pyproj import Proj
Proj({'init': 'epsg:2193', 'no_defs': True}, preserve_flags=True)

On the following setup:

C:\...> conda list anaconda$
# packages in environment at C:\ProgramData\Anaconda3:
#
# Name                    Version                   Build  Channel
anaconda                  2019.07                  py37_0

pyproj.__version__:
	1.9.6
pyproj.proj_version_str:
	 0.5.20
sys.version.replace('\n', ' '):
	 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
platform.platform()
	 Windows-10-10.0.16299-SP0

I fixed the error by editing the file datadir.py
changed .../Anaconda3\share\proj
to ...\Anaconda3\Library\share

@samcollie
Copy link

@smcateer 's solution works for me as well! Although, I have the same specs but the path is

pyproj_datadir="C:\Anaconda3\Lib\site-packages\pyproj\data"

Thanks @smcateer !!

@shakedk
Copy link

shakedk commented Sep 12, 2019

Why is this closed?
I installed geopandas using:
conda install -c conda-forge geopandas

And couldn't possibly understand how to fix it. @smcateer solution works, but this should be fixed in conda iteself. Took me only 72 hours to understand how to tackle this :(

@snowman2
Copy link
Member

Why is this closed?

Not an issue on pyproj>=2

@snowman2
Copy link
Member

@shakedk, you will need to re-create your environment and use the strict option:
https://conda-forge.org/

conda config --add channels conda-forge
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -n geo geopandas
conda activate geo
(geo) ....

@shakedk
Copy link

shakedk commented Sep 12, 2019

Will this installed version 2 and up? Because using it regularly installed pyproj 1.9.6 and I wasn't able to update it manually.

@snowman2
Copy link
Member

Yes, it should.

@ratnanil
Copy link

@smcateer's answer (#134 (comment)) worked for me as well.. and for all those who somehow missed where to look for the file datadir.py (like I did), it's located here in the folder \Lib\site-packages\pyproj of the environment in question.

@arc12
Copy link

arc12 commented Nov 10, 2019

+1 for comment #134

@kaimoxuan123
Copy link

import os
3. os.environ['PROJ_LIB']=r"C:[... path to ….]\Anaconda3\Library\share"

it reaally works for me !!! Thanks a lot.

@zuzhaoye
Copy link

  1. Delete the folder 'pyproj' from 'site-package' (somewhere at ...\Anaconda\Lib\site-packages\pyproj, if you use Anaconda)
  2. then 'pip install pyproj'
    I faced the same problem and it worked for me. The root cause turned out to be Anaconda didn't install enough files.

@Nuwan-UWA
Copy link

  1. Delete the folder 'pyproj' from 'site-package' (somewhere at ...\Anaconda\Lib\site-packages\pyproj, if you use Anaconda)
  2. then 'pip install pyproj'
    I faced the same problem and it worked for me. The root cause turned out to be Anaconda didn't install enough files.

it really works..as simple as it is. Thanks @zuzhaoye

@Tokusei
Copy link

Tokusei commented Mar 5, 2020

Hi, I tried the most recent post. Replacing pyproj installed from anaconda and installing it with pip. It no longer gives an error, However the function has unexpected behavior.

crs = {'init' :'epsg:3395'}
provinces_GPDF.plot()
print(provinces_GPDF.crs)
provinces_GPDF.to_crs(crs)
print(provinces_GPDF.crs)

returns

{'init': 'epsg:4326'}
{'init': 'epsg:4326'}

the function is running, but does not return the newly updated CRS

Edit: I didnt save the updated dataframe into the variable needed to set
provinces_GPDF.to_crs(crs)
Edit2: works with PyProj1.9.6 with Descartes installed

@azizasaber
Copy link

I had the same problem with pycharm. And I didnt have most of the folders that u guys mentioned above in my pyproj folder. And its version was 1.9. So I updated it to version 2... using conda. I think u should do it with conda rather than pip.

During the installation, I found out that when I was installing geopandas it hadn't install MKL-2020.0 properly. When I updadet pyproj, MKL-2020.0 installed as well. And after that everything worked well and I had the needed folders in pyproj folder!

@hafez-ahmad
Copy link

gdf.to_crs('epsg = 4682')
Traceback (most recent call last):

File "", line 1, in
gdf.to_crs('epsg = 4682')

File "C:\Users\hafez\anaconda3\envs\ocean\lib\site-packages\geopandas\geodataframe.py", line 534, in to_crs
geom = df.geometry.to_crs(crs=crs, epsg=epsg)

File "C:\Users\hafez\anaconda3\envs\ocean\lib\site-packages\geopandas\geoseries.py", line 423, in to_crs
proj_in = pyproj.Proj(self.crs, preserve_units=True)

File "C:\Users\hafez\anaconda3\envs\ocean\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'

@answerquest
Copy link

answerquest commented May 26, 2020

@zuzhaoye 's solution:

  1. Delete the folder 'pyproj' from 'site-package' (somewhere at ...\Anaconda\Lib\site-packages\pyproj, if you use Anaconda)
  2. then 'pip install pyproj'

Worked for me, albeit it throws up a warning message, documenting it here:

C:\Users\nsheth3\AppData\Local\Continuum\anaconda3\lib\site-packages\pyproj\crs\crs.py:53: FutureWarning:'+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6

@arckay88
Copy link

After a bit of frigging around I was able to figure out the problem. I downloaded the repo source code and copied the folder pyproj-master.zip\pyproj-master\lib\pyproj\data and copied to the location indicated in site-packages/pyproj/data/epsgdatadir.py (making sure the names lined up, I had to rename the folder from data to proj

After that, the library worked perfectly. Perhaps it is a problem with using Anaconda to install it, but this extremely crucial data folder was simply not copied, or was possibly copied to the wrong location.

this one fixed mine

@pyproj4 pyproj4 locked as resolved and limited conversation to collaborators Jan 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests