Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Upgrade to Python 3 #551
Upgrade to Python 3 #551
Comments
|
I think you should deliver both extensions for Python2 as well as for Python3. Best way would be to compile against Homebrew's Python3. This way you can just deliver the Postgresapp with an out of the box working Python2 and if someone wants to use Python3, he just have to do "brew install python3" and everything is up and running. To be honest, I'm a little lazy myself. I could build plpythin3u separately. But if you do, life's much easier. ;) |
|
We've been working on this topic a bit. We can't simply link with Homebrew's Python3, because we have no idea what Python version they use, and they might change the default version of Python 3. There is no binary compatibility with the different minor versions (eg. if you compile PostgreSQL with Python 3.8 it won't work with Python 3.7 or Python 3.9). However, we've discovered that the Python 3 offers an optional stable ABI. If PostgreSQL would use that ABI, then it wouldn't matter which version of Python 3 the user has installed. I have been able to patch PostgreSQL to use the stable ABI, and I will submit my patch to the PostgreSQL project. But there's only one problem left: I don't want to require Homebrew. Postgres.app is designed for a wide audience, and I don't know how many of them use homebrew. I want our users to be able to use Python 3 without having to learn how to use a package manager. I believe that most people who use Python3 on macOS installed it using one of the following methods:
If somehow possible, I want Postgres.app to be compatible with all of them. This means we would probably need to set some environment variable to tell plpython.so where to look for Python, and add some way for the user to select which Python Postgres.app uses. |
|
In case anybody feels like testing, here's a build of Postgres.app with PostgreSQL 13 and Python 3. It requires the official Python 3.8 from python.org to be installed. https://eggerapps-downloads.s3.eu-west-1.amazonaws.com/Postgres-dev-13.dmg |
|
Are you envisioning including a prompt the user would receive when they first open the app that asks which Python install to use? |
That could be confusing for Postgres.app users who don't use Python. Our idea was to try to autodetect if the user has Python 3 installed, and set environment variables accordingly. (Eg. check for official Python, if not installed check Homebrew, if that isn't installed check for Xcode, ...) There could be a preference setting that allows you to override the autodetected setting, or set it manually when Postgres.app doesn't find it. Thinking about this, I wonder if a global setting is sufficient, or if we need one setting per server (so you could have servers with different Pythons). Anyway, the idea would be that we set the variables The following doesn't work:
For some reason the Another potential issue is that sometimes the framework is called "Python" (eg. the python.org installer) and sometimes it's "Python3" (eg. Xcode). For now we've been able to get a proof of concept working with symbolic links (we were able to run a test function with Homebrew, Xcode, and official Python). So it looks like it should work in principle, but we still need to figure out how to get it all working automatically, and ideally without requiring the user to type |
Isn't this the runtime protection of SIP that prevents inheriting dynamic linker related environment variables when forking? The same reason why So, the approach with symlinks seems to be more promising to me. Out of curiosity - what is requiring root rights on that route? |
|
@tbussmann Yes, it sounds like that is exactly what's going on. I think that the SIP runtime protection blocks the DYLD_* variables from being passed on to postgres worker processes. I thought that giving postgres the com.apple.security.cs.allow-dyld-environment-variables entitlement would be enough, but when the postmaster doesn't pass the variable on to workers there's no point. So here are all the approaches that I can think of that we could use to solve this problem
|
|
Can't we use approach 3 with a location within our application bundle like |
That would probably break the code signature of the Postgres.app bundle. It used to be no problem if it happened after first launch, but macOS has gotten stricter and started checking the code signature more frequently. I recall Apple saying in one of last years WWDC videos that going forward bundle modifications will only be allowed if they keep the code signature intact. I think the easiest way for us to support Python3 would be to do the following:
|
|
One other question: Is this to enable people to use Python 3 with PL/Python, or is there another use case? (I'm author of a PostgreSQL book and recommend installing PostgresApp, so I just want to anticipate changes I may need to make in the book.) |
|
@anthonydb Yes! Right now there's only |
|
With todays release of PostgreSQL 13, we now finally include Python 3 support. However, since macOS does not include Python 3, you now need to manually install Python 3.8 from Python.org. I've documented the necessary steps here: https://postgresapp.com/documentation/plpython.html If you try to activate
That's not a very good user experience, but I don't really know how to improve this. I hope people read the docs or at least find this issue when they google the error message. If would welcome suggestions how to improve this situation. Since a lot of people have trouble using extensions, maybe we should add some more docs about extensions in a prominent location of the home page? If you don't want to use the official Python.org installer, it may be possible to create a symlink at PostgreSQL 13 in Postgres.app no longer includes Python 2.7. Building PostgreSQL with 2.7 and 3 would make the build process a lot more complicated, and since Python 2.7 reached end-of-life almost a year ago I think ending support for it seems reasonable to me. If you absolutely need 2.7 support, you can continue using Postgres.app with PostgreSQL 12. |
With Python 2 reaching end of life, it's time for Postgres.app to also upgrade to Python 3.
Postgres.app has always just linked to the system Python, which until recently has been Python 2.7. I think macOS 10.15 started bundling Python 3.
I'm not sure how to change the Postgres.app build process to include support for Python 3, while also maintaining compatibility with macOS < 10.15.
A further complication is that Apple claimed that they will stop shipping scripting languages with the OS at some point altogether, however it remains to be seen if they will actually go through with this. If this happens, we will probably have to start bundling scripting languages with Postgres.app.
Any input on the issue is appreciated.
Adding support for Python 3 was previously discussed in #207, but unfortunately nobody came up with a good way to solve the problem then.