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

Python 3.11 Windows ARM64 #246

Open
infinitepower18 opened this issue Apr 6, 2022 · 11 comments
Open

Python 3.11 Windows ARM64 #246

infinitepower18 opened this issue Apr 6, 2022 · 11 comments

Comments

@infinitepower18
Copy link

Python has started offering embeddables and installers for Python 3.11 Windows ARM64. Is this something pynsist can include, if I want to distribute a native Windows ARM build?

https://www.python.org/downloads/release/python-3110a7/

You could probably add arm64 as an option for bitness in the config file.

@takluyver
Copy link
Owner

Downloading the embedded Python build would be easy enough. I don't know how to tell NSIS to make an ARM64 installer, though - can you find out about that?

I would also guess that few packages have pre-built Windows ARM64 wheels, which might limit how useful it is.

@infinitepower18
Copy link
Author

The installer doesn't need to be in ARM64 I think. Right now there's not much info about Python on ARM64, since Python 3.11 is still in alpha stage. I guess once it becomes official we will see more packages getting ARM64 builds

@takluyver
Copy link
Owner

Ah, I see, NSIS will make an x86 exe which runs in an emulator on ARM Windows, according to https://sourceforge.net/p/nsis/feature-requests/547/ . At some point I guess it will be possible to build a native ARM64 installer, but not yet, it appears.

@infinitepower18
Copy link
Author

Got a Raspberry Pi 400 which I can use to run Windows on ARM and the ARM version of Python 3.11 on, tested it with my program and it seems to be working perfectly fine without any changes.

IMG_7368

So it's just a matter of pynsist adding the option for ARM64.

@takluyver
Copy link
Owner

Do you want to make a PR?

The code to make the URL to download Python from is here:

pynsist/nsist/__init__.py

Lines 182 to 190 in 0e05f3e

def _python_download_url_filename(self):
version = self.py_version
bitness = self.py_bitness
filename = 'python-{}-embed-{}.zip'.format(version,
'amd64' if bitness==64 else 'win32')
version_minus_prerelease = re.sub(r'(a|b|rc)\d+$', '', self.py_version)
return 'https://www.python.org/ftp/python/{0}/{1}'.format(
version_minus_prerelease, filename), filename

In the config file, I'd suggest introducing a new parameter like arch = arm64 as an alternative to the bitness option (though the old option needs to keep working). Here's the relevant code:

('bitness', False),

args['py_bitness'] = config.getint('Python', 'bitness', fallback=DEFAULT_BITNESS)

You'll also need to adapt anywhere else that uses bitness, like the prepare_msvcrt method, the commands module generating .exe wrappers, and the wheels module finding wheels to download.

@infinitepower18
Copy link
Author

infinitepower18 commented Apr 19, 2022

It would probably be better to wait until Python 3.11 goes out of beta. I somewhat got a messy implementation working, the installer will run fine on ARM systems via emulation and it will install the ARM64 version of the Python program. You can even build the installer on your regular x86 machine however for tkinter to work, you have to get the relevant files off an ARM Python installation and you need a device which can run Windows on ARM for that. So far I haven't tested builds with tkinter as I've now removed Windows from my Raspberry so have to go through the whole install process again.

I'll keep the changes to my own fork for now and will PR when the official release of 3.11 is out.

@takluyver
Copy link
Owner

Sounds good, thanks. 👍

Tkinter is kind of a pain in general - it's not in the embeddable builds, which is fair enough, but as far as I know there's no good way to get it without the full Python installer - there's no package on PyPI or anything. I'm not going to solve that, but if someone does, I hope Pynsist can take advantage of it.

@infinitepower18
Copy link
Author

Happy to report that after building the ARM installer with the modified pynsist and including the ARM tkinter files my program successfully installs and runs in ARM64 native.

Screenshot 2022-04-19 214035

However the installer is suggesting the Program Files (x86) directory by default when selecting Install for all users, so need to figure that out. There is a Program Files (Arm) folder but some sources are saying its for ARM32 apps. Notepad++ ARM64 version simply installs to the normal Program Files folder.

Screenshot 2022-04-19 214121

@takluyver
Copy link
Owner

There's a workaround in the code because the NSIS MultiUser extension used the wrong program files on x86-64 machines. Maybe that needs to be used on ARM too:

pynsist/nsist/pyapp.nsi

Lines 258 to 265 in 0e05f3e

[% if ib.py_bitness == 64 %]
Function correct_prog_files
; The multiuser machinery doesn't know about the different Program files
; folder for 64-bit applications. Override the install dir it set.
StrCmp $MultiUser.InstallMode AllUsers 0 +2
StrCpy $INSTDIR "$PROGRAMFILES64\${MULTIUSER_INSTALLMODE_INSTDIR}"
FunctionEnd
[% endif %]

@infinitepower18
Copy link
Author

Seems like it's not as easy as I thought.

While working on my next update of my program, I had to include one new package but turns out they don't have a specific arm64 Windows wheel yet. Link

The other packages I used if I'm not mistaken had universal wheels, which is why I didn't run into any problems.

So pynsist needs to look for specific Windows ARM64 wheels too.

@takluyver
Copy link
Owner

Yup, it's easy for pure Python projects, but quite probably a headache for any project with compiled extension modules.

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

No branches or pull requests

2 participants