是否可以为 raspberry pi 安装 glpk?

is it possible to install glpk for raspberry pi?

我想在 raspberry pi 上安装 glpk 3. 我使用 testEnv 创建的虚拟环境 venv

python3 -m venv testEnv

我已经安装成功了pyomo

python3 -m pip install pyomo

但是当我尝试

python3 -m pip install glpk

我收到以下错误:

(testEnv) pi@raspberrypi:~/Desktop/MA-AU/Software-Test $ python3 -m pip install glpk
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting glpk
  Using cached https://files.pythonhosted.org/packages/ca/26/198ec4b9d1b752404a7ecb104bd1b4bfba711feaadabc0b1407de87adb26/glpk-0.4.6.tar.gz
  Installing build dependencies ... done
Building wheels for collected packages: glpk
  Running setup.py bdist_wheel for glpk ... error
  Complete output from command /home/pi/Desktop/MA-AU/Software-Test/testEnv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-zpb2w0ff/glpk/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-0x260le1 --python-tag cp37:
  running bdist_wheel
  running build
  running build_ext
  building 'glpk' extension
  creating build
  creating build/temp.linux-armv7l-3.7
  creating build/temp.linux-armv7l-3.7/src
  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DVERSION_NUMBER="0.4.6" -I/home/pi/Desktop/MA-AU/Software-Test/testEnv/include -I/usr/include/python3.7m -c src/glpk.c -o build/temp.linux-armv7l-3.7/src/glpk.o
  In file included from src/glpk.c:21:
  src/lp.h:24:10: fatal error: glpk.h: Datei oder Verzeichnis nicht gefunden
   #include <glpk.h>
            ^~~~~~~~
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for glpk
  Running setup.py clean for glpk
Failed to build glpk
Installing collected packages: glpk
  Running setup.py install for glpk ... error
    Complete output from command /home/pi/Desktop/MA-AU/Software-Test/testEnv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-zpb2w0ff/glpk/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-5egd9fdm/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/Desktop/MA-AU/Software-Test/testEnv/include/site/python3.7/glpk:
    running install
    /tmp/pip-build-env-l3jwi8g7/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      setuptools.SetuptoolsDeprecationWarning,
    running build
    running build_ext
    building 'glpk' extension
    creating build
    creating build/temp.linux-armv7l-3.7
    creating build/temp.linux-armv7l-3.7/src
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DVERSION_NUMBER="0.4.6" -I/home/pi/Desktop/MA-AU/Software-Test/testEnv/include -I/usr/include/python3.7m -c src/glpk.c -o build/temp.linux-armv7l-3.7/src/glpk.o
    In file included from src/glpk.c:21:
    src/lp.h:24:10: fatal error: glpk.h: Datei oder Verzeichnis nicht gefunden
     #include <glpk.h>
              ^~~~~~~~
    compilation terminated.
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/home/pi/Desktop/MA-AU/Software-Test/testEnv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-zpb2w0ff/glpk/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-5egd9fdm/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/Desktop/MA-AU/Software-Test/testEnv/include/site/python3.7/glpk" failed with error code 1 in /tmp/pip-install-zpb2w0ff/glpk/

Raspberry Pi OS:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

提前感谢您的帮助!

当您在尝试安装 Python 库时收到有关缺少 .h 文件的错误时,原因通常是 Python 库依赖于 C 库,Python 找不到包 — 可能是因为您还没有安装它!

在这种情况下,运行 apt-get install libglpk-dev 应该为您获取必要的库和 headers。