user1093541
user1093541

Reputation: 39

Attempting to install FSPS raises environment variable error

I am trying to install the python interface of the fsps program. However, when I run sudo python3 setup.py install I get the error:

Traceback (most recent call last):
  File "/mnt/c/Users/Lea/Documents/HSCFA/python-fsps/fsps/__init__.py", line 26, in <module>
    ev = os.environ["SPS_HOME"]
  File "/usr/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'SPS_HOME'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 87, in <module>
    from fsps import __version__  # NOQA
  File "/mnt/c/Users/Lea/Documents/HSCFA/python-fsps/fsps/__init__.py", line 28, in <module>
    raise ImportError("You need to have the SPS_HOME environment variable")
ImportError: You need to have the SPS_HOME environment variable

However, I have already set the SPS_HOME variable in my ~./bashrc file, including the export statement. I have tried using the source ~/.bashrc command, restarting the shell, and also typing export SPS_HOME directly into the command line, but nothing fixes it. There was a similar question to this posted a while ago, where the poster's issue was due to the fact that they had not logged in as root when adding the environment variable to the .bashrc file, but they were running the installation command as root with sudo. I assume that they were able to fix this by logging in as root and re-adding the environment variable to .bashrc. However, this fix is not working for me, and I was wondering if anyone had any other ideas.I am using Ubuntu 20.04 and Windows 10.

Upvotes: 1

Views: 299

Answers (2)

SorenIsANerd
SorenIsANerd

Reputation: 13

sudo is the culprit. Commands invoked through sudo don't inherit the environment from the caller's shell by default. sudo -E python3 setup.py install should disable this behavior.

Upvotes: 0

Leonardo Dagnino
Leonardo Dagnino

Reputation: 3225

Your problem here is that sudo, for security reasons, does not pass your environment variables to the command you execute. If you wish to do so, you may pass the -E flag to sudo, or specify it explicitly:

sudo SPS_HOME=$SPS_HOME python3 setup.py install

Upvotes: 1

Related Questions