0

I am trying to use Bloomberg python API. I need to set BLPAPI_ROOT environment variable for this. I added,

export BLPAPI_ROOT="/home/user/Downloads/blpapi_cpp_3.6.3.1"
export PATH=$PATH:$BLPAPI_ROOT

to my .bashrc file and ran source .bashrc. Now, when I open python shell and do,

print os.environ['BLPAPI_ROOT'] 

it gives me correct output. But when the same this runs inside the setup.py provided, it throws a

Traceback (most recent call last):
  File "setup.py", line 27, in <module>
    blpapiRoot = os.environ['BLPAPI_ROOT']
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'BLPAPI_ROOT'

What am I missing here ?

System : Ubuntu 12.04 Python 2.7

Nishant Shah
  • 13
  • 2
  • 4
  • 1
    The error will occur when you run your script with another security context e.g. using sudo –  Sep 26 '13 at 05:21
  • But without sudo,I get permission denied as it is trying to access /usr/local/lib/python2.7/dist-packages/blpapi. Is there a correct way of doing this that I am missing ? – Nishant Shah Sep 26 '13 at 06:05
  • Maybe use `chmod` to change permissions for that folder and then try. – chackerian Feb 01 '17 at 13:42
  • is there a solution for the same problem using windows and python version 3.9 ? – D.L Nov 20 '20 at 17:00

2 Answers2

1

I would try using it the following way:

import os
try:
    os.environ['BLPAPI_ROOT'] = "/home/user/Downloads/blpapi_cpp_3.6.3.1"
except EnvironmentError:
    sys.exit(1)
rolandvarga
  • 126
  • 1
  • 10
1

This is quite old, but for anyone searching, you can get around this by setting sudo to keep the environmental variable BLPAPI_ROOT, a la keep environmental variables using sudo.

sudo visudo

Then add:

Defaults env_keep +="BLPAPI_ROOT"

You can now run:

sudo python setup.py install

and it should work just fine.

Community
  • 1
  • 1