Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend to use pip to install pygobject #374

Merged
merged 1 commit into from May 16, 2018
Merged

Recommend to use pip to install pygobject #374

merged 1 commit into from May 16, 2018

Conversation

SanketDG
Copy link
Contributor

Recently, pygobject can be installed from pip. So this PR
recommends the user to install pygobject through pip.

It also deletes redundant code that handles different operating
systems which was sometimes found to be incorrect.

Fixes #371

I am really not sure if I missed any sensitive branches that just needed to be there, I will need some help on that.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Recently, pygobject can be installed from pip. So this PR
recommends the user to install pygobject through pip.

It also deletes redundant code that handles different operating
systems which was sometimes found to be incorrect.

Fixes #371
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this branch, and it didn't work for me - because pygobject couldn't be installed. The first failure was due to pkg-config not being available; but then it was failing because cairo apparently wasn't available (although it's definitely installed as a system package).

Assuming you were able to get this to work, there is, at the very least, the need for some extra documentation. Given the numerous failure modes, it also suggests that there is a need for vastly improved error messages. It's not just as simple as pip install pygobject - because that command won't run out of the box on a stock Ubuntu system.

@SanketDG
Copy link
Contributor Author

've tried this branch, and it didn't work for me - because pygobject couldn't be installed. The first failure was due to pkg-config not being available; but then it was failing because cairo apparently wasn't available (although it's definitely installed as a system package).

Sorry I do not understand how these errors happen. Some help would be appreciated.

Given the numerous failure modes, it also suggests that there is a need for vastly improved error messages. It's not just as simple as pip install pygobject - because that command won't run out of the box on a stock Ubuntu system.

I agree, do we want to provide an error message with installing pip or beyond that. It all depends on how far we want this to go to help the user.

@freakboy3742
Copy link
Member

I don't know what to tell you other than "on a clean Ubuntu 17.10 install, pip install pyobject didn't complete". I don't use Ubuntu on a daily basis, so I'll need to to defer to someone with more experience to diagnose the cause.

@danyeaw
Copy link
Member

danyeaw commented Feb 22, 2018

The official docs say that it is possible to install. Following that exact procedure fails for me also in Ubuntu 17.10.

Package gobject-introspection-1.0 was not found in the pkg-config search path.

so I ran

apt-get install libgirepository1.0-dev

Fedora, CentOS, RHEL, etc.: gobject-introspection-devel
Debian, Ubuntu, Mint, etc.: libgirepository1.0-dev
Arch: gobject-introspection

pip install finished installing fine after that. I checked out your branch and the Gtk+ tutorials run fine. So while it is great that pygobject is pip installable, the dependencies it needs are not. 😞
So maybe this might be worthwhile if we could either check that gobject-introspection is installed, or make really clear documentation on what must be installed prior to using Toga. Unfortunately it is not the pybee's knees 🐝 since we would be dependent on Linux distro development packages.

@freakboy3742
Copy link
Member

Some binary dependencies are going to be inevitable. The great nasty symlink hack shouldn't be, though. If we can replace the symlink hack with something that will reliably work with a few "apt-get install" commands, then we should do that.

However, adding libgirepository1.0-dev didn't fix the problem for me; I'm still seeing the following errors (partial transcript - there's a lot more than this, but I can't easily copy&paste from a GTK terminal to Mac):

...
running build_ext
Package cairo was not founding the pig-config search path
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 0']' returned non-zero exit status 1

----------------------------------------
Failed building wheel for pygobject
running setup.py clean for pygobject
Running setup.py bdist_wheel for pycairo ... error
...
Package cairo was not founding the pig-config search path
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1

----------------------------------------
Failed building wheel for pycairo

@danyeaw
Copy link
Member

danyeaw commented Feb 22, 2018

It sounds like someone needs to startup some clean Linux vm's and figure out the build dependencies on Ubuntu, Arch, and Fedora. In Ubuntu:

sudo apt build-dep pygobject

Should install all necessary files. @SanketDG is that something you are interested in testing?

@SanketDG
Copy link
Contributor Author

SanketDG commented Feb 23, 2018

I tested on Fedora, and it seems like its

sudo dnf builddep pygobject3 python3-gobject

@SanketDG
Copy link
Contributor Author

It sounds like someone needs to startup some clean Linux vm's and figure out the build dependencies on Ubuntu, Arch, and Fedora

I could be willing to do this, but it'd take a while before I shell out time for this.

@SanketDG
Copy link
Contributor Author

I found this guide http://pygobject.readthedocs.io/en/latest/getting_started.html, looks like we can use this as a resource with the builddep command.

I have never used Arch, and I can't seem to find a similar builddep command with a simple google search. Maybe this is a good excuse to finally try out Arch.

@danyeaw
Copy link
Member

danyeaw commented Mar 4, 2018

I setup and tested this on a Ubuntu and Arch Vagrant VM, I'm also trying to get Fedora setup but it is being difficult.
@freakboy3742 I can reproduce the error you were getting. I found that if I have the introspection package installed from above, I can successfully install it by installing pycairo first:

pip install pycairo
pip install pygobject

I don't think doing the installation of the build-dep is required.

@ArchKudo
Copy link
Contributor

ArchKudo commented Mar 4, 2018

IMO, The checks must be present, but the user must be recommended not use system libraries as it may break things on upgrade!

On Arch Linux I have the current setup:

  • Use a local python installation using pyenv
  • Required system packages: Only gobject-introspection, However it along with a lot of other dependencies(python-gobject) are anyways installed when installing Gnome DE
  • Create a virtualenv
  • Install pycairo and pygobject using pip

@freakboy3742
Copy link
Member

Ok - on my clean Ubuntu 17.10.1 install, these instructions still aren't working for me.

If I install gobject-introspection, I get errors about pkg-config not existing. I didn't install developer tools by default, so that makes sense. If I install pkg-config, I get the same errors about cairo and glib not existing - but I'm running Gnome, so something cairo and glib is installed.

@danyeaw
Copy link
Member

danyeaw commented Mar 5, 2018

@freakboy3742 I'm trying to spin up a fresh 17.10 vm now to see if I can reproduce this. I installed some extra things during my earlier tests in order to build pyenv like build-essentials, so I'll remove all that and use just a normal virtualenv with the system python.

@danyeaw
Copy link
Member

danyeaw commented Mar 5, 2018

@freakboy3742 this is what worked for me:

sudo apt-get install pkgconfig libgirepository1.0-dev libcairo2-dev python3-dev
pyvenv myvenv
source myvenv/bin/activate
pip install wheel
pip install pycairo
pip install pygobject

@danyeaw
Copy link
Member

danyeaw commented Mar 10, 2018

I worked to get the PyGObject Development Environment docs updated.

@freakboy3742
Copy link
Member

I get some really weird messages following those instructions. The installation of pycairo and pygobject both seem to fail - or at least, they print errors that make it look like they failed:

rkm@ubuntu:~/mac/projects/beeware$ python3 -m venv lvenv
rkm@ubuntu:~/mac/projects/beeware$ . lvenv/bin/activate
(lvenv) rkm@ubuntu:~/mac/projects/beeware$ pip install wheel
Collecting wheel
  Using cached wheel-0.30.0-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.30.0
(lvenv) rkm@ubuntu:~/mac/projects/beeware$ pip install pygobject
Collecting pygobject
  Using cached PyGObject-3.27.5.tar.gz
Collecting pycairo>=1.11.1 (from pygobject)
Building wheels for collected packages: pygobject
  Running setup.py bdist_wheel for pygobject ... error
  Complete output from command /media/psf/Home/projects/beeware/lvenv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-wqgwsrhk/pygobject/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/tmp1beuwsfepip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/tests
  copying tests/test_docstring.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/testmodule.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_generictreemodel.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_gi.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_gio.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_iochannel.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_atoms.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_mainloop.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_import_machinery.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_gtype.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_error.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/compathelper.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_overrides_pango.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_object_marshaling.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_signal.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_repository.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/runtests.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_overrides_glib.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_glib.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_typeclass.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_properties.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_interface.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_resulttuple.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_overrides_gdk.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/conftest.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_unknown.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_cairo.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/__init__.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_everything.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_ossig.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_fields.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_pygtkcompat.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_option.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_thread.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_gobject.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_overrides_gtk.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_subprocess.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_source.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_gdbus.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/helper.py -> build/lib.linux-x86_64-3.6/tests
  copying tests/test_internal_api.py -> build/lib.linux-x86_64-3.6/tests
  creating build/lib.linux-x86_64-3.6/gi
  copying gi/_signalhelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_constants.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/module.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/importer.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/docstring.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_ossighelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_propertyhelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/pygtkcompat.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_option.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/types.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/__init__.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_error.py -> build/lib.linux-x86_64-3.6/gi
  creating build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/generictreemodel.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/pygtkcompat.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/__init__.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  creating build/lib.linux-x86_64-3.6/tests/gi
  copying tests/gi/__init__.py -> build/lib.linux-x86_64-3.6/tests/gi
  creating build/lib.linux-x86_64-3.6/tests/gi/overrides
  copying tests/gi/overrides/Regress.py -> build/lib.linux-x86_64-3.6/tests/gi/overrides
  copying tests/gi/overrides/__init__.py -> build/lib.linux-x86_64-3.6/tests/gi/overrides
  creating build/lib.linux-x86_64-3.6/gi/repository
  copying gi/repository/__init__.py -> build/lib.linux-x86_64-3.6/gi/repository
  creating build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gio.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gdk.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/keysyms.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gtk.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GIMarshallingTests.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GLib.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/__init__.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GObject.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Pango.py -> build/lib.linux-x86_64-3.6/gi/overrides
  running build_ext
  pycairo: new API
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 824, in <module>
      main()
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 819, in main
      zip_safe=False,
    File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/media/psf/Home/projects/beeware/lvenv/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 204, in run
      self.run_command('build')
    File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 673, in run
      self._setup_extensions()
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 669, in _setup_extensions
      add_pycairo(gi_cairo_ext)
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 654, in add_pycairo
      ext.include_dirs += [get_pycairo_include_dir()]
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 571, in get_pycairo_include_dir
      include_dir = find_path(find_new_api())
    File "/tmp/pip-build-wqgwsrhk/pygobject/setup.py", line 521, in find_new_api
      import cairo
  ModuleNotFoundError: No module named 'cairo'
  
  ----------------------------------------
  Failed building wheel for pygobject
  Running setup.py clean for pygobject
Failed to build pygobject
Installing collected packages: pycairo, pygobject
  Running setup.py install for pygobject ... done
Successfully installed pycairo-1.16.3 pygobject-3.27.5

But, it looks like the last message is correct, because:

(lvenv) rkm@ubuntu:~/mac/projects/beeware$ python3
Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_version('Gtk', '3.0')
>>> from gi.repository import Gtk, Gio, GLib
>>> 

it all seems to work.

So - I'm not wild about getting error messages during an install that are false alarms, but this will be less fragile than the symlink approach.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code for this looks good to go (although there's still a bunch of code comments that can be trimmed).

However, there's a whole lot of documentation extra required before this is mergeable. In particular, the fact that the installation process might look like a failure (but is actually a success) is something that needs to be addressed.

We can also add pygobject as an install-requires dependency of the toga-gtk backend.

@SanketDG
Copy link
Contributor Author

The code for this looks good to go (although there's still a bunch of code comments that can be trimmed).

Code comments? I removed the majority of stuff.

However, there's a whole lot of documentation extra required before this is mergeable. In particular, the fact that the installation process might look like a failure (but is actually a success) is something that needs to be addressed.

Sure, what extra stuff do we want to mention? Also can you mention what OS were you using in that weird fail message but successful build?

@danyeaw
Copy link
Member

danyeaw commented Mar 11, 2018

@SanketDG I think what @freakboy3742 was referring to for code comments is:

# If Gtk can't be imported, it may be because we're in a virtualenv,
# and the system python libraries aren't visible. This can be fixed by
# creating a symlink into the site-packages
# Try creating a symlink to the system library location.
# base_packages_dir is where the packages installed by the package manager
# can be found.
# gi_system_install_path is where gi can be found in the packages dir.
# installer_command is the command the user can run to install gi.

@freakboy3742
Copy link
Member

@SanketDG We need sufficient instructions that someone with no experience with Toga can get to a working version of the tutorial. So - anywhere that discusses the initial installation process needs to reference the new requirements. There's already sections talking about the dependencies that need to be installed on Linux - we need to make sure those lists have been updated.

I was running my tests (and getting the odd error) on Ubuntu 17.10

@SanketDG
Copy link
Contributor Author

SanketDG commented Mar 13, 2018

I was running my tests (and getting the odd error) on Ubuntu 17.10

I am getting this too, both on Ubuntu 17.10 and Fedora 27, could it be somehow related to how pygobject sets up their setup.py? It looks like it tries to find pycairo before installing it as one of the dependencies.

@danyeaw
Copy link
Member

danyeaw commented Apr 1, 2018

@SanketDG Are you still interested in helping to finish the documentation for how to pip install pygobject? This would be an awesome contribution if we matured this PR to a point where it could be merged.

@danyeaw danyeaw mentioned this pull request Apr 5, 2018
4 tasks
@danyeaw danyeaw merged commit 8a5fca7 into beeware:master May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants