1

I am currently struggling to get pyproj to initialize when running in PyCharm. Oddly enough, I am able to get it to work in cmd.

The version of pyproj I am using is 1.9.6, and the version of proj4 I am using is 5.2.0.

The following runs without error using the Python interpreter:

import pyproj
pyproj.Proj({'init': 'epsg:26910'})

However, when running from PyCharm the following error is produced:

Traceback (most recent call last):
  File "C:/Users/frankbr/.PyCharmCE2019.2/config/scratches/scratch.py", line 5, in <module>
    pyproj.Proj({'init': 'epsg:26910'})
  File "C:\Users\frankbr\.conda\envs\pyfor_env\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'

Due to other dependencies, and the fact that it runs in cmd (and Travis tests) without error, I am hoping to find a solution that only requires modification to PyCharm.

3

The normal way to use conda is to activate an environment where proj is installed, which sets PROJ_LIB to the correct path.

However, it's not always possible to run "activate", for instance from PyCharm or Spyder IDEs. Here is my workaround that works for a few scenarios:

import os

# workaround if activate is not called
conda_prefix = os.environ.get('CONDA_PREFIX', '')
if conda_prefix and not os.path.isdir(os.environ.get('PROJ_LIB', '')):
    proj_lib = os.path.join(conda_prefix, 'Library', 'share', 'proj')
    if os.path.isdir(proj_lib):
        os.environ['PROJ_LIB'] = proj_lib
    else:  # assume older
        proj_lib = os.path.join(conda_prefix, 'Library', 'share')
        os.environ['PROJ_LIB'] = proj_lib
1

The environmental variable PROJ_LIB needed to be set to the location of the files used by the proj library. In my case that was in the following directory:

'C:\\Users\\frankbr\\.conda\\envs\\pyfor_env\\Library\\share'

Editing the build configuration in PyCharm allows for modification of environmental variables. See this tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.