Skip to content

[Python-pip] I can't install toga #1780

Open
@Heus-Sueh

Description

@Heus-Sueh

What happened?

If I try to install the toga library through pip inside .venv it gives me this error:

❯ pip install toga
Collecting toga
  Using cached toga-0.4.1-py3-none-any.whl.metadata (4.0 kB)
Collecting toga-gtk==0.4.1 (from toga)
  Using cached toga_gtk-0.4.1-py3-none-any.whl.metadata (3.0 kB)
Collecting gbulb>=0.5.3 (from toga-gtk==0.4.1->toga)
  Using cached gbulb-0.6.4-py3-none-any.whl (17 kB)
Requirement already satisfied: pycairo>=1.17.0 in /nix/store/67mw87bh762ismbnbd239xw59yv76p9k-python3.12-pycairo-1.25.1/lib/python3.12/site-packages (from toga-gtk==0.4.1->toga) (1.25.1)
Collecting pygobject>=3.46.0 (from toga-gtk==0.4.1->toga)
  Using cached PyGObject-3.46.0.tar.gz (723 kB)
  Installing build dependencies ... error
  error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [45 lines of output]
      Collecting setuptools
        Using cached setuptools-69.0.3-py3-none-any.whl.metadata (6.3 kB)
      Collecting wheel
        Using cached wheel-0.42.0-py3-none-any.whl.metadata (2.2 kB)
      Collecting pycairo
        Using cached pycairo-1.25.1.tar.gz (347 kB)
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Installing backend dependencies: started
        Installing backend dependencies: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Using cached setuptools-69.0.3-py3-none-any.whl (819 kB)
      Using cached wheel-0.42.0-py3-none-any.whl (65 kB)
      Building wheels for collected packages: pycairo
        Building wheel for pycairo (pyproject.toml): started
        Building wheel for pycairo (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error
      
        × Building wheel for pycairo (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [15 lines of output]
            running bdist_wheel
            running build
            running build_py
            creating build
            creating build/lib.linux-x86_64-cpython-312
            creating build/lib.linux-x86_64-cpython-312/cairo
            copying cairo/__init__.py -> build/lib.linux-x86_64-cpython-312/cairo
            copying cairo/__init__.pyi -> build/lib.linux-x86_64-cpython-312/cairo
            copying cairo/py.typed -> build/lib.linux-x86_64-cpython-312/cairo
            running build_ext
            Package cairo was not found in the pkg-config search path.
            Perhaps you should add the directory containing `cairo.pc'
            to the PKG_CONFIG_PATH environment variable
            Package 'cairo', required by 'virtual:world', not found
            Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' returned non-zero exit status 1.
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for pycairo
      Failed to build pycairo
      ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
(devbox) 

installing cairo or pycairo doesn't solve it

Steps to reproduce

Create a devbox with the latest version of python and try to install toga through .venv

Command

add, shell

devbox.json

{
  "packages": [
    "pipx@latest",
    "python@latest",
    "cairo@latest",
    "python312Packages.pycairo@latest"
  ],
  "shell": {
    "init_hook": [
      ". $VENV_DIR/bin/activate"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

Devbox version

0.9.0

Nix version

nix (Nix) 2.18.1

What system does this bug occur on?

Linux (x86-64)

Debug logs

No response

Activity

added
bugSomething isn't working
triageIssue needs triage
on Feb 4, 2024
Heus-Sueh

Heus-Sueh commented on Feb 4, 2024

@Heus-Sueh
Author

Sorry if this isn't the right place to report the bug or ask for help

gcurtis

gcurtis commented on Feb 27, 2024

@gcurtis
Collaborator

Hi @Heus-Sueh, you're definitely in the right place! It looks like toga requires a few native libraries.

Try removing python312Packages.pycairo (we recommend just using a pip virtual environment) and installing the dev outputs for cairo and gobject-introspection. You'll also need pkg-config so that pip can find the libraries:

dx rm python312Packages.pycairo
dx add pkg-config@latest
dx add cairo@latest -o out,dev
dx add gobject-introspection@latest -o out,dev

That should get you a devbox.json that looks something like:

{
  "packages": {
    "pipx":       "latest",
    "python":     "latest",
    "pkg-config": "latest",
    "cairo": {
      "version": "latest",
      "outputs": ["out", "dev"]
    },
    "gobject-introspection": {
      "version": "latest",
      "outputs": ["out", "dev"]
    }
  },
  "shell": {
    "init_hook": [
      ". $VENV_DIR/bin/activate"
    ]
  }
}
self-assigned this
on Feb 27, 2024
added
pythonSupport for Python, pip, Poetry, etc.
linuxLinux systems
linkerRelated to linking (ld, ld.so or dyld)
x86-64x86-64 systems
and removed
triageIssue needs triage
on Feb 27, 2024
Heus-Sueh

Heus-Sueh commented on Feb 27, 2024

@Heus-Sueh
Author

Hi @Heus-Sueh, you're definitely in the right place! It looks like toga requires a few native libraries.

Try removing python312Packages.pycairo (we recommend just using a pip virtual environment) and installing the dev outputs for cairo and gobject-introspection. You'll also need pkg-config so that pip can find the libraries:

dx rm python312Packages.pycairo
dx add pkg-config@latest
dx add cairo@latest -o out,dev
dx add gobject-introspection@latest -o out,dev

That should get you a devbox.json that looks something like:

{
  "packages": {
    "pipx":       "latest",
    "python":     "latest",
    "pkg-config": "latest",
    "cairo": {
      "version": "latest",
      "outputs": ["out", "dev"]
    },
    "gobject-introspection": {
      "version": "latest",
      "outputs": ["out", "dev"]
    }
  },
  "shell": {
    "init_hook": [
      ". $VENV_DIR/bin/activate"
    ]
  }
}

Thanks for the help, I'll test this solution later

Heus-Sueh

Heus-Sueh commented on Mar 21, 2024

@Heus-Sueh
Author

Sorry for the delay, I just tested it but now it's giving me this dependency error: OSError: libfontconfig.so.1: cannot open shared object file: No such file or directory

Heus-Sueh

Heus-Sueh commented on Mar 21, 2024

@Heus-Sueh
Author

full log:

(.venv) (devbox) ➜  pokemon_demo-Toga git:(main) ✗ briefcase dev

[pokemon-demo] Starting in dev mode...
===========================================================================
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/src/pokemon_demo/__main__.py", line 4, in <module>
    main().main_loop()
    ^^^^^^
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/src/pokemon_demo/app.py", line 142, in main
    return MainApp("Pokemon Demo", "org.pokemon.demo")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/virtenv/python/.venv/lib/python3.12/site-packages/toga/app.py", line 466, in __init__
    self.factory = get_platform_factory()
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/virtenv/python/.venv/lib/python3.12/site-packages/toga/platform.py", line 111, in get_platform_factory
    factory = importlib.import_module(f"{backend.value}.factory")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/nix/profile/default/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/virtenv/python/.venv/lib/python3.12/site-packages/toga_gtk/factory.py", line 1, in <module>
    from . import dialogs
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/virtenv/python/.venv/lib/python3.12/site-packages/toga_gtk/dialogs.py", line 4, in <module>
    from .libs import Gtk
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/virtenv/python/.venv/lib/python3.12/site-packages/toga_gtk/libs/__init__.py", line 1, in <module>
    from .fontconfig import FontConfig  # noqa: F401, F403
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/virtenv/python/.venv/lib/python3.12/site-packages/toga_gtk/libs/fontconfig.py", line 5, in <module>
    fontconfig = CDLL(libfontconfig)
                 ^^^^^^^^^^^^^^^^^^^
  File "/var/home/heus/Documents/Projects/VSCodium/Python/Briefcase-Projects/pokemon_demo-Toga/.devbox/nix/profile/default/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: libfontconfig.so.1: cannot open shared object file: No such file or directory

Problem running app pokemon-demo.

https://stackoverflow.com/questions/77247893/modulenotfounderror-no-module-named-distutils-in-python-3-12

Heus-Sueh

Heus-Sueh commented on Apr 1, 2024

@Heus-Sueh
Author

@gcurtis Sorry to ping you, but could you help me with this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglinkerRelated to linking (ld, ld.so or dyld)linuxLinux systemspythonSupport for Python, pip, Poetry, etc.x86-64x86-64 systems

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @gcurtis@Heus-Sueh

      Issue actions

        [Python-pip] I can't install toga · Issue #1780 · jetify-com/devbox