【问题标题】:Attempting to install FSPS raises environment variable error尝试安装 FSPS 引发环境变量错误
【发布时间】:2020-10-03 12:43:39
【问题描述】:

我正在尝试安装 fsps 程序的 python 接口。但是,当我运行 sudo python3 setup.py install 时,我得到了错误:

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

但是,我已经在 ~./bashrc 文件中设置了 SPS_HOME 变量,包括导出语句。我尝试使用source ~/.bashrc 命令,重新启动shell,并在命令行中直接输入export SPS_HOME,但没有任何修复。前段时间有一个类似的问题,发帖者的问题是由于他们在将环境变量添加到 .bashrc 文件时没有以 root 身份登录,但是他们以 root 身份运行安装命令须藤。我假设他们能够通过以 root 身份登录并将环境变量重新添加到 .bashrc 来解决此问题。但是,此修复对我不起作用,我想知道是否有人有其他想法。我使用的是 Ubuntu 20.04 和 Windows 10。

【问题讨论】:

    标签: bash ubuntu environment-variables installation


    【解决方案1】:

    sudo 是罪魁祸首。默认情况下,通过sudo 调用的命令不会从调用者的 shell 继承环境。 sudo -E python3 setup.py install 应该禁用此行为。

    【讨论】:

    • 为什么用 sudo 打开 .bashrc 然后添加变量不起作用?另外,sudo -E 到底是做什么的?
    • 另外sudo -E 给出了奇怪的输出:usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] [VAR=value] [-i|-s] [&lt;command&gt;] usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] file ... 。而且它似乎不起作用,因为运行 sudo python3 setup.py install 给出了同样的错误。
    • 我想我应该更清楚。我已经更新了答案以显示完整的命令行。
    【解决方案2】:

    您的问题是sudo,出于安全原因,不会将您的环境变量传递给您执行的命令。如果您愿意,可以将-E 标志传递给sudo,或明确指定:

    sudo SPS_HOME=$SPS_HOME python3 setup.py install
    

    【讨论】:

    • 谢谢! SPS_HOME=$SPS_HOME 到底是做什么的?
    • 运行sudo SPS_HOME=$SPS_HOME python3 setup.py install 给出错误Traceback (most recent call last): File "setup.py", line 87, in &lt;module&gt; from fsps import __version__ # NOQA File "/mnt/c/Users/Lea/Documents/HSCFA/python-fsps/fsps/__init__.py", line 38, in &lt;module&gt; raise ImportError("Your FSPS version does not seem to be under git version " ImportError: Your FSPS version does not seem to be under git version control. FSPS is available on github at https://github.com/cconroy20/fsps and should be cloned from there我下载不正确吗?
    • SPS_HOME=$SPS_HOMESPS_HOME 的当前值传递给 sudo - 它会在 = 的右侧替换您的当前值。和SPS_HOME=/the/actual/path是一样的,但是既然你已经在你的bashrc中设置了SPS_HOME,应该会更实用。
    • 看起来python-fsps 要求fspsgit 一起下载以验证版本 - 您可以通过运行cd &lt;your desired fsps directory&gt; 然后git clone https://github.com/cconroy20/fsps.git 来做到这一点。您可能想要移动/删除已有的目录。
    • 谢谢!但现在它说File "setup.py", line 87, in &lt;module&gt; from fsps import __version__ # NOQA File "/mnt/c/Users/Lea/Documents/HSCFA/python-fsps/fsps/__init__.py", line 44, in &lt;module&gt; raise ImportError("Your FSPS version does not have correct history." ImportError: Your FSPS version does not have correct history. Perhaps you need to pull the most up-to-date FSPS version. Please make sure that you have the following commits in your git history, preferably with the last listed commit the same as your current FSPS commit githash: 6ad10,b5250,a23e4,45f96,05584
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    相关资源
    最近更新 更多