1

I need help to install a package using apt install in the Raspberry Pi using the Python version I installed using pyenv. I already tried using pip, but the installation fails. The specific package I tried to install is pyqt5, for more info. The code is running in a Raspberry Pi OS 12 Bookworm.

My goal is to use the most recent Python version installed with pyenv to create a virtual environment, development environment, and use --system-site-packages to transfer the package. The problem is that apt install always sees the system OS installation of Python, which is several versions behind the one we use for development.

I found a person asking the same question in GitHub 8 years ago and the answer at the time was that it is not possible. I hope things have evolved for the better since then.

I share the traceback of the error as requested by comments:

  Collecting pyqt5
  Using cached PyQt5-5.15.11.tar.gz (3.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      pyproject.toml: line 14: the legacy use of 'license' is deprecated and will be removed in SIP v7.0.0, use an SPDX license expression and 'license-files' instead
      Traceback (most recent call last):
        File "/home/meca-vision/Documents/VisionClean4-repository/2visionclean-env2/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/meca-vision/Documents/VisionClean4-repository/2visionclean-env2/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/meca-vision/Documents/VisionClean4-repository/2visionclean-env2/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 152, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-lhigqra4/overlay/lib/python3.11/site-packages/sipbuild/api.py", line 28, in build_wheel
          project = AbstractProject.bootstrap('wheel',
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-lhigqra4/overlay/lib/python3.11/site-packages/sipbuild/abstract_project.py", line 74, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/tmp/pip-build-env-lhigqra4/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 633, in setup
          self.apply_user_defaults(tool)
        File "/tmp/pip-install-wi408778/pyqt5_6eae56fded3d4c2eb48fdd123619bf15/project.py", line 68, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-lhigqra4/overlay/lib/python3.11/site-packages/pyqtbuild/project.py", line 51, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-lhigqra4/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 243, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/tmp/pip-build-env-lhigqra4/overlay/lib/python3.11/site-packages/pyqtbuild/builder.py", line 49, in apply_user_defaults
          raise PyProjectOptionException('qmake',
      sipbuild.pyproject.PyProjectOptionException
      [end of output]
15
  • 5
    "I found a person asking the same question in github without getting a solution 8 years ago." There is an answer there and the answer is: "you can't". System package managers can only install packages into the system. Once you stopped using system package managers and started to use language package managers you're completely on your own. If there're precompiled language packages — good for you, download, install and use them. If there are no — ouch, you should compile yourself. Commented Jun 4 at 13:24
  • 2
    “but the installation fails” How? Is there a traceback you can share? Commented Jun 4 at 14:49
  • 3
    apt installs modules specially created for default Python. These modules may not work with other Python versions. But you may try to copy it from system folder to your environment folder and maybe it will work. Commented Jun 4 at 15:19
  • 4
    Your raspberry pi link gives you a possible solution: use the --system-site-packages flag. This will allow you to create a venv that can see the system site packages. No need to involve pyenv. If you wanted to use pyenv so you can use a different python version, then this will never work. pyqt is compiled against the API of a specific python version, which changes from version to version. You will instead need to compile pyqt yourself. Commented Jun 4 at 17:18
  • 2
    My gut feeling is that you should rather continue investing your time and energy figuring out why installing pyqt5 in a Python virtual environment with pip fails. I believe this should work. -- This or work with the Python that is installed with apt (and still use virtual environments with --system-site-packages). -- Everything else will likely be an absurdly uphill battle that barely anyone will be able to help you with simply because probably no one else tries to do what you are trying to do. Commented Jun 4 at 17:25

1 Answer 1

0

I fired up my raspberry and checked the versions. The Python version on your bookworm should be 3.11 and with apt you can install pyqt 5.15.9 which then can be use in your venv using the '--system-site-packages' option. I had to adapt my own projects to the provided versions of raspberry environments so I would not have to deal with those issues.

I believe part of the reason this happens, is piwheels that is used by your raspberry.

piwheels.org states, that pyqt5 will fail to build in bookworm

screenshot piwheels pyqt5 installation

Source: https://www.piwheels.org/project/pyqt5/

Maybe you could try to install another distro like Ubuntu 24.04 on your raspi, this might work.

Sign up to request clarification or add additional context in comments.

2 Comments

Does this answer the question "How can I use Python packages installed with apt-get in a Python interpreter installed with pyenv?"? By my read, it's telling the OP that they shouldn't be using pyenv -- it may solve their individual problem, but it's not the question that was asked. (I actually do have my own use-entirely-different-tools suggestion, but I added it as a comment, not an answer, since only answers to the direct question belong in the answer section).
I hear ya. The only reason I posted this as an answer was to attach the screenshot to have a snapshot of the current state of the pip package combined with the distro and pyqt versions. This was not supposed to become an accepted answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.