pyproj: "no arguments in initialization list" runtime error

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?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 69 (13 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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"  

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.

  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.

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

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.

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”

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

Just had the same trouble after re-installing all my packages and the solution of @jfnk worked perfect for me but I didn’t need to download any folder, just put the following code in order to make it work : os.environ['PROJ_LIB']=r"C:\Users\[...replace accordingly...]\Anaconda3\Library\share"

Same observation. Issue is gone with upgrading to 2.1.* version.

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?

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

@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

@smcateer’s answer (https://github.com/pyproj4/pyproj/issues/134#issuecomment-521846924) 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.

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

@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.

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.

Just fyi, this issue has gone away for me with the 2.1.* versions.

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

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

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.