pygobject / pycairo

Python bindings for cairo
https://pycairo.readthedocs.io
Other
623 stars 85 forks source link

Can't install latest pycairo (1.20.0) on OSX 10.15 #213

Open gijzelaerr opened 3 years ago

gijzelaerr commented 3 years ago

hi! When I try to pip install pycairo on OS X 10.15 I get the error:

  [WARNING] This wheel needs a higher macOS version than is set in MACOSX_DEPLOYMENT_TARGET variable.  To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least 11_0 or recreate these files with lower MACOSX_DEPLOYMENT_TARGET:

an older version (1.19.1) installs fine. Seems that 1.20.0 depends on the unreleased OSX beta?

more logs:

  Copying pycairo.egg-info to build/bdist.macosx-10.14.6-x86_64/wheel/pycairo-1.20.0-py3.8.egg-info
  running install_scripts
  [WARNING] This wheel needs a higher macOS version than is set in MACOSX_DEPLOYMENT_TARGET variable.  To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least 11_0 or recreate these files with lower MACOSX_DEPLOYMENT_TARGET:
  build/bdist.macosx-10.14.6-x86_64/wheel/cairo/_cairo.cpython-38-darwin.soTraceback (most recent call last):
    File "/Users/gijs/Work/surfnet/python-eduvpn-client/venv/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
      main()
    File "/Users/gijs/Work/surfnet/python-eduvpn-client/venv/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/gijs/Work/surfnet/python-eduvpn-client/venv/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 204, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 216, in build_wheel
      return self._build_with_temp_dir(['bdist_wheel'], '.whl',
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 202, in _build_with_temp_dir
      self.run_setup()
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 253, in run_setup
      super(_BuildMetaLegacyBackend,
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 145, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 568, in <module>
      main()
    File "setup.py", line 535, in main
      setup(
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 328, in run
      impl_tag, abi_tag, plat_tag = self.get_tag()
    File "/private/var/folders/3x/3x7fz5857gbc0ygf80vy0cs00000gq/T/pip-build-env-5f39welu/overlay/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 278, in get_tag
      assert tag in supported_tags, "would build wheel with unsupported tag {}".format(tag)
  AssertionError: would build wheel with unsupported tag ('cp38', 'cp38', 'macosx_11_0_x86_64')
  ----------------------------------------
  ERROR: Failed building wheel for pycairo
lazka commented 3 years ago

There is nothing macos specific in pycairo. Maybe your pip is confused, try pip cache purge

gijzelaerr commented 3 years ago

seems to have the same result: https://gist.github.com/gijzelaerr/57d58be34d9f98fb3dcc1e82242b6312

lazka commented 3 years ago

thanks. the one thing that changed in 1.20 is that I opted pycairo into "PEP 517" by adding a pyproject.toml file to the package. I guess this triggers some bug in pip your case.

No idea right now, sorry.

lazka commented 3 years ago

There are also some arm64 warnings in there. are you on arm64?

gijzelaerr commented 3 years ago

nope, just a normal x86_64 OSX 10.15. I guess the osx toolchain is already preparing the binaries for the upcoming switch to arm arch.

lazka commented 3 years ago

ok. The only related error I can find is https://old.reddit.com/r/vscode/comments/iwoh5d/help_error_in_installing_pylint_in_virtual/ which isn't that helpful.

Maybe updating python in homebrew would help (the errors suggest it was installed with an older macos version).

lazka commented 3 years ago

And consider filing a bug with wheel: https://github.com/pypa/wheel Maybe they know more.

gijzelaerr commented 3 years ago

Interesting, If I use python 3.9.0 using pyenv the problem goes away. So yes, I guess it is some odd issue in combination with the vanilla python 3.8 bundled with OS X 10.15 and wheel / pip.

justvanrossum commented 3 years ago

I'm curious: why are there no macOS wheels for the latest release on PyPI?

stuaxo commented 3 years ago

@justvanrossum probably some extra work needs doing here - WHL support was getting added, at around the same time travis decided to start charging + everything had to move to github actions.

infirit commented 3 years ago

If I remember correctly there will be a wheel with the next release of pycairo.

naveen521kk commented 3 years ago

Not for macOS though? Maybe if you want macOS wheels, it is easy to build(at least I can help) it but you would need to convince @lazka for that.

stuaxo commented 3 years ago

@naveen521kk If you want help reviewing a PR I'm up for that, though even more time starved than last time :)

I've been away from this long enough to have forgotten what the status of WHLs is here :-/

lazka commented 3 years ago

The problem is that wheels would break pygobject (then there would be two different libcairo in the same process), so I'm not that enthusiastic about it. But I guess pycairo has more users...

justvanrossum commented 3 years ago

No wheels, no painless installation, no happy users. I've honestly been avoiding pycairo because it's such a pain to get installed reliably across platforms. Not every Python user has (the right) development tools installed to build from the sources. (In my circles most do not.)

stuaxo commented 3 years ago

This is something at the edge of my knowledge, is it that if a library is contained in a whl and the system with the same name there is a clash and an issue of which to choose ?

Could we do some mangling of the name when it comes to the one we put in the whl, so we at least have some control over which we choose ?

naveen521kk commented 3 years ago

@lazka Maybe we can upload wheel to the releases section and not to PyPi. User's can install from there if needed and I don't think pip will ever find it. So I think there wont be any problem with pygobject though.

@stuaxo Python handles it. First, priority for loading the library is for the .libs in the wheel. Atleast that is so on unixish OS. This isn't so for windows though, but the first one loaded will be in the same directory, so the wheels do work on windows.

Also, lazka, does pygobject link with pycairo or directly with cairo itself? Because if we statically link the produced output and if pygobject simply links with pycairo there won't be any problem I think.

naveen521kk commented 3 years ago

Again, @lazka does pygobject links with pycairo directly or with Cairo? If we link statically with cairo will pygobject just use the one from pycairo?

lazka commented 3 years ago

pygobject links against both pycairo and cairo.

naveen521kk commented 3 years ago

pygobject queries for pkg-config right? So what if we create those accordingly? such that it doesn't link directly to cairo. and we create wheels where we link to cairo statically?

lazka commented 3 years ago

pygobject gets cairo pointers from gtk and passes them to pycairo and vice versa. I don't think pkg-config is relevant here.

naveen521kk commented 3 years ago

Ok, then nothing can be done to make it work with the wheels provided right? Then I think wheels can be build but not uploaded to PyPI, instead just kept in the releases section, and have a mention of it in the installation section.

justvanrossum commented 3 years ago

Then I think wheels can be build but not uploaded to PyPI, instead just kept in the releases section, and have a mention of it in the installation section.

Then projects can't depend on pycairo automatically, making their CI cumbersome, and making it impossible to install such a project seamlessly with pypi.

I have no clue about the problems that cause this and how to solve them, I'd just like to point out the obvious: that this would be a very sad situation for pycairo indeed.

naveen521kk commented 3 years ago

Maybe upload wheels to testpypi? I could understand the problems with pygobject, yes I don't know a way to fix it though. I at first thought it doesn't link to Cairo directly, instead, it just links to pycairo, which inturn will link to Cairo. If that's the case if we have wheels statically linked to Cairo, then pygobject doesn't need to link with Cairo, instead just linking with pycairo will suffice and the .pc file pycairo generates will also be changed according. But I don't think that is the case as @lazka told. Having two different versions of Cairo installed would create a lot of problems... Rather I would like to have it only in specific condition only when the users need it, the wheels should be used. Or maybe a new pypi package for wheels, but I still don't know which should be the best.

On the other side on Windows, this wasn't a problem at all. pygobject can't be directly installed there, it needs MSYS2 project, so there were no problems creating a wheel.

stuaxo commented 3 years ago

This isn't the only library that's had the issue of wanting to use libraries that may clash with system libraries.

There was some discussion around this for auditwheel here https://discuss.python.org/t/delocate-auditwheel-but-for-windows/2589/8

Dealocate looks like a tool that aims to solve clashes with system libraries on mac, maybe it can solve that part of the problem for us: https://pypi.org/project/delocate/

EDIT: Since we mentioned windows, there is a similar tool: https://pypi.org/project/delvewheel/ [/EDIT]

I have to admit to getting a little confused every time I re-visit this ticket, it might be useful to make a table of the different scenarios.

naveen521kk commented 3 years ago

I don't think that solves the problem of two different Cairo instance and the compatibility between the two.

stuaxo commented 3 years ago

To get on the same page, what are the different versions that may clash ?

Lets assume homebrew the user is on OSX with homebrew + we didn't know about this issue and had WHLs for pycairo and pygobject.

Is this a reasonable list of the cairo libs that could clash ?

cairo installed via homebrew cairo that was installed as part of the pycairo whl cairo that was installed as part of the pygobject whl

(And lets assume they are all different, so either different versions or different compilation options)

naveen521kk commented 3 years ago

Well, what pygobject does is pick the pointer from gtk and give it to pycairo. The pointer can be incompatible if gtk was compiled under different Cairo(either version or compilation options) and could cause Segmentation Faults. And this is the main reason why @lazka is hesitant to build wheels.

stuaxo commented 3 years ago

I'm totally onboard with being cautious.

Is this for any use of pygobject, or only when doing something like drawing with cairo in Gtk ?

What's the smallest amount of code that will show us things are broken, is it simply import gi or do we need to do something more?

I might be able to give you remote access to a mac to try and create the breaking scenarios and see if deallocate can help.

naveen521kk commented 3 years ago

Maybe rather than simply an import statement run the example at https://pygobject.readthedocs.io/en/latest/guide/cairo_integration.html

tate1650 commented 3 years ago

I know this thread is quite a few months old at this point (not sure if it's best to just continue this thread for my question or start a new one; I'm gonna guess the former), but I'm wondering: has there been any decision made as to whether a .whl file will be provided anywhere for MacOS, whether that be on PyPI, TestPyPI, or the Releases page?

I work with an online high school CS education organization, and we have our own Python graphics package that depends on pycairo. At the moment, we're stuck with "installing" the package using a giant zip file with a bunch of different versions of our dependencies (including pycairo) that get loaded in depending on what OS you run the package on. It works, but it's definitely not the most convenient thing in the world. I've been working for a couple months on adding it to PyPI and having it install packages directly so the process is a lot smoother and the package is a lot less bulky.

While the install works fine on Windows, there are error messages on MacOS if you don't install cairo with brew or another package manager first. However, we'd like to allow our users on Mac to pip install our graphics package without needing to install Homebrew on their system or use some other package manager. We ideally want the installation process to be one simple command, especially since some of our users are high school students who may not be super familiar with cmd/terminal. But we'd need wheels for pycairo on MacOS in order to do that, at least as far as I know. That being said, is there any place we can access such a file either now or sometime in the near future? Even if it's not available on the main PyPI site, having it available on TestPyPI or anywhere else that pip can access would be really useful for us (and I'm sure other people developing packages that depend on pycairo, too).

TheMatt2 commented 1 year ago

This issue was fixed for me by specifying a MACOSX_DEPLOYMENT_TARGET version using the following command.

MACOSX_DEPLOYMENT_TARGET=10.3 pip3 install pycairo

MacOS 12.6.2 Python 3.11.1 pip 22.3.1 Homebrew 3.6.16 cairo 1.16.0 Apple clang version 11.0.3 (Xcode tools installed, Xcode not installed)

Based on this Stackoverflow answer, it seems the issue is compiler installed on the Mac is older than the MacOS version. https://stackoverflow.com/a/72118836/8524178

The MacOS version is 12.6.2, but if I run clang --version it returns 11.0.3

Trying to install normally fails with the error (abridged):

       creating build/temp.macosx-12-x86_64-cpython-311
      creating build/temp.macosx-12-x86_64-cpython-311/cairo
      clang ... -O3 -Wall -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=23 -DPYCAIRO_VERSION_MICRO=0 -I/usr/local/Cellar/cairo/1.16.0_5/include/cairo ...
      clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=12'
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

Trying to install again with an intentionally invalid MACOSX_DEPLOYMENT_TARGET=0 gives the helpful error message:

MACOSX_DEPLOYMENT_TARGET=0 pip3 install pycairo   
      creating build/temp.macosx-12-x86_64-cpython-311
      creating build/temp.macosx-12-x86_64-cpython-311/cairo
      clang ... -O3 -Wall -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=23 -DPYCAIRO_VERSION_MICRO=0 -I/usr/local/Cellar/cairo/1.16.0_5/include/cairo ...
      error: $MACOSX_DEPLOYMENT_TARGET mismatch: now "0" but "12" during configure; must use 10.3 or later
      [end of output]

Trying the install again with the specified "10.3" version number succeeds!

MACOSX_DEPLOYMENT_TARGET=10.3 pip3 install pycairo