I'm wondering if anyone has experience with cross-compiling to windows with pyo3 and maturin.
The pyo3 docs say:
Cross compiling PyO3 modules is relatively straightforward and
requires a few pieces of software:
A toolchain for your target. The appropriate options in your Cargo
.config for the platform you're targeting and the toolchain you are
using. A Python interpreter that's already been compiled for your
target. The headers that match the above interpreter.
I've found the interpreter from here, but I don't understand how to get a windows python interpreter and libraries, or even what that means exactly.
I'm using maturin to build the python wheels and it works well on OS X, but I don't know how to start cross-compiling for windows.
Can anyone help me out?
The goal is a wheel per Python version / architecture / OS.
An easy way to achieve this is through external runners (e.g. gitub runners) and an action that compiles the package using maturin for each of the platforms.
Here is how hyperjson does it.
pyo3 now has experimental Windows feature to bypass this process entirely using python3-dll-a. Read more here.
Related
My python script is finished and working and I want to compile and have other users enjoy/benefit from it. The users don't need to install Pycharm or Visual Studio Code, something like an executable file or run in a command prompt then execute on their local machine or is there a way to convert it on a Tampermonkey Script?
How do I achieve this? Thank you very much in advance!
Googled and Youtubed but it's not what I'm looking for.
This question is probably answered multiple times, but the PyInstaller module is a great way to generate an executable that will run on Windows, and an app that will run on macOS.
Check out PyInstaller on PyPI.org: https://pypi.org/project/pyinstaller/
Project description
PyPI PyPI - Python Version Read the Docs (version) PyPI - Downloads
PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules.
Documentation:
https://pyinstaller.org/
Code:
https://github.com/pyinstaller/pyinstaller
PyInstaller reads a Python script written by you. It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files – including the active Python interpreter! – and puts them with your script in a single folder, or optionally in a single executable file.
PyInstaller is tested against Windows, macOS, and GNU/Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a GNU/Linux app you run it in GNU/Linux, etc. PyInstaller has been used successfully with AIX, Solaris, FreeBSD and OpenBSD, but is not tested against them as part of the continuous integration tests.
Main Advantages
Works out-of-the-box with any Python version 3.7-3.11.
Fully multi-platform, and uses the OS support to load the dynamic libraries, thus ensuring full compatibility.
Correctly bundles the major Python packages such as numpy, PyQt5, PySide2, PyQt6, PySide6, wxPython, matplotlib and others out-of-the-box.
Compatible with many 3rd-party packages out-of-the-box. (All the required tricks to make external packages work are already integrated.)
Works with code signing on macOS.
Bundles MS Visual C++ DLLs on Windows.
Installation
PyInstaller is available on PyPI. You can install it through pip:
pip install pyinstaller
Requirements and Tested Platforms
Python:
3.7-3.11. Note that Python 3.10.0 contains a bug making it unsupportable by PyInstaller. PyInstaller will also not work with beta releases of Python 3.12.
tinyaes 1.0+ (only if using bytecode encryption). Instead of installing tinyaes, pip install pyinstaller[encryption] instead.
Windows (32bit/64bit):
PyInstaller should work on Windows 7 or newer, but we only officially support Windows 8+.
Support for Python installed from the Windows store without using virtual environments requires PyInstaller 4.4 or later.
Note that Windows on arm64 is not yet supported. If you have such a device and want to help us add arm64 support then please let us know on our issue tracker.
Linux:
GNU libc based distributions on architectures x86_64, aarch64, i686, ppc64le, s390x.
musl libc based distributions on architectures x86_64, aarch64.
ldd: Console application to print the shared libraries required by each program or shared library. This typically can be found in the distribution-package glibc or libc-bin.
objdump: Console application to display information from object files. This typically can be found in the distribution-package binutils.
objcopy: Console application to copy and translate object files. This typically can be found in the distribution-package binutils, too.
Raspberry Pi users on armv5-armv7 should add piwheels as an extra index url then pip install pyinstaller as usual.
macOS (x86_64 or arm64):
macOS 10.15 (Catalina) or newer.
Supports building universal2 applications provided that your installation of Python and all your dependencies are also compiled universal2.
Usage
Basic usage is very simple, just run it against your main script:
pyinstaller /path/to/yourscript.py
For more details, see the manual.
Untested Platforms
The following platforms have been contributed and any feedback or enhancements on these are welcome.
FreeBSD
ldd
Solaris
ldd
objdump
AIX
AIX 6.1 or newer. PyInstaller will not work with statically linked Python libraries.
ldd
Linux on any other libc implementation/architecture combination not listed above.
Before using any contributed platform, you need to build the PyInstaller bootloader. This will happen automatically when you pip install pyinstaller provided that you have an appropriate C compiler (typically either gcc or clang) and zlib’s development headers already installed.
Support
Official debugging guide: https://pyinstaller.org/en/v5.6.2/when-things-go-wrong.html
Assorted user contributed help topics: https://github.com/pyinstaller/pyinstaller/wiki
Web based Q&A forums: https://github.com/pyinstaller/pyinstaller/discussions
Email based Q&A forums: https://groups.google.com/g/pyinstaller
Changes in this Release
You can find a detailed list of changes in this release in the Changelog section of the manual.
I am developing a plugin for plex media server. Plex uses Python 2.7 for plugin system. I need to use python-levenshtein package, which needs to be compiled for different systems.
I found python-Levenshtein wheels (manylinux, macos, arm, windows), but the wheel for Windows compiled with VS 2008 (msvcr90.dll). And plex embeded python compiled with VS 2013 (msvcr130.dll).
Being on Windows 10 how can i compile python package with different VS runtimes?
Note: compiling extensions for versions of Python other than the official releases is not supported by the Python team, and has to be supported by the product - in this case, Plex. So assuming Plex hasn't provided a way to do this, everything below is hacks and workarounds.
Also, if the library developer is not doing the builds then you're trying to cover for them, which means you are basically at their "level" and will need to know their code as well as they do. Welcome to open source software :)
Finally, this only applies to legacy Python 2. If anyone reading this is on Python 3.5 or later, just install the latest Visual Studio and use the latest compiler - the entire 14.x line is compatible and will work fine with recent Python versions.
Assuming you've been careful about how the extension interacts with the C Runtime, it's often safe to compile your extension against the "wrong" C runtime version. Things to watch out for here are:
allocating memory that will be freed by Python
freeing memory that was allocated by Python
passing/getting file descriptors or FILE* pointers to/from Python
setting any global settings like encoding or locale
writing to standard streams
If all of these are isolated, then you'll just end up with two C runtimes in memory and they won't try to interact.
Now, if for some reason this can't be done, you can try compiling the extension using a later toolset. The easiest way to do this is:
get the source code (I'm assuming setup.py based build via wheel)
open VS 2013 Developer Command prompt
run set DISTUTILS_USE_SDK=1 (this will bypass MSVC detection)
run set MSSdk=1 (also needed to bypass detection on legacy Python 2)
run python setup.py bdist_wheel (you may need to install wheel into Python first)
Now you can take the wheel file and install it however you normally would, perhaps by extracting/copying the files or passing the full filename to pip.
In general, there's a very high chance that simply building the extension will not succeed. In that case, you'll have to modify the source code to work - a lot of names were deprecated and removed in the three MSVC versions between VC 9.0 and VC 12.0, and so you won't see deprecation warnings for any of them.
If the library developer has already made their library work with Python 3, many of the fixes should be there but may not be detected (as Python 3 either used VC 10.0, which didn't need the fixes, or VC 14.x, which may be detected as _MSC_VER >= 1900 and won't detect VC 12.0). They may appreciate it if you contribute any fixes you make so that the next person is helped, but many library developers are dropping support for versions of Python prior to 3.5 now and so they may not be interested in maintaining legacy support.
I have compiled a PyXMLSec lib successful on Ubuntu. I want to create a windows-installer for this lib (i.e PyXMLSec-win32-python27.exe). Can I create it from my Ubuntu or it must be from Win32? How can I create it? I prefer from Ubuntu because in Windows, I have some bugs.
Thanks.
You should build and test the installer on Windows. (If you don't test it on Windows, you don't know it works on Windows.)
The commonly used free installation software products used for making Windows installers typically include Wix and Inno Setup. For ease of use, I prefer Inno Setup; it has some free GUIs (linked to from the site itself) for creating the setup scripts used to build the installer, is pretty flexible without any custom work on your part, and easily extendable using it's built-in Object Pascal-based scripting language.
Wix, however, supports building MSI-based installers that use Windows Installer. MSI installs are often required by corporate network administrators because they allow pushing the installation out to computers in the network domain easily. It's harder to work with unless you're pretty familiar with it, so it may not be suitable for a one-off installer requirement like you seem to need.
I want to make an installation file for my python source code"
You have to use NSIS, InnoSetup, BitRock Installer, IzPack or equivalent to produce a platform installer. So you have to take the binary result produced on the first part and package it for os distribution. Almost all the installer systems are thinked for Windows systems. Cross platform : Zero Install, IzPack ... If you use IzPack you can have a cross platform installer paying the price of including a jvm.
And i Believe This >> HELP Can be Light of Your Way ;)
Have a look at the documentation for Build Distribution:
python setup.py bdist --format=msi
I like to use Scapy with Python v2.7 under Windows 7.
How can I install the required module pypcap for Python 2.7?
Will it be possible to make Python scripts depending on Scapy into standalone Windows applications using a distribution tool such as py2exe?
The particular Python distribution I am using is Enthought Python distribution 7.02.
Intrusive update: please note that this answer is outdated, with recent versions (>=2.4.0) scapy will ONLY require Npcap (or Winpcap) to work, and IPython for the console. Have a look at the official windows page
In case someone needs Scapy for 64-bit + Python 2.7, I've uploaded the binaries here:
https://github.com/Kondziowy/scapy_win64
dnet-1.12.win-amd64-py2.7.exe
pcap-1.1.win-amd64-py2.7.exe
scapy-2.2.0.win-amd64.exe
In addition, you probably need to install WinPcap from the official site
Compiling it yourself required a few fixes - I'll commit them upstream soon.
Q: how can i install required module pypcap
Using Scapy with Windows 7 is possible, but it does not exactly work out of the box. An install guide can be found here:
http://www.secdev.org/projects/scapy/doc/installation.html#windows
I strongly recommend to switch to python 2.6, as this will make your live much easier.
When you insist on 2.7 you will have to compile some of the require modules yourself. Also, some key modules like pypcap have to be patched before they can be compiled with python 2.7 (see pycap patch).
Here you will find some guidance on how to build the modules.
Q: will it be possible to make python scripts depending on scapy into standalone windows applications
Yes and no. While you can use py2exe to build a an EXE from your python code. Scapy uses WinPcap which you have to install in addition to your application.
Dirk Loss provides an Windows installer for the dnet package for Python 2.7. Together with the Windows installer for the pypcap package for Python 2.7 I was able to run Scapy successfully on Python 2.7 on Windows.
A LOT OF ANSWERS ARE OUTDATED !
Latest scapy version, that you can download on the official GitHub page:
https://github.com/secdev/scapy
Works without the old hand-compiled dependencies!
They are two easy requirements: IPython (for the console) and npcap (or winpcap)
You may follow the official tutorial here:
http://scapy.readthedocs.io/en/latest/installation.html#windows
Using the link posted by circus, I created binary installations for Scapy for python 2.7.x 32bit. Link for the setups (with dependencies) https://github.com/Kondziowy/scapy_win64
If you don't have limitations forcing you to work with python2, you can try scapy3k from http://github.com/phaethon/scapy or pip install scapy-python3.
It does not require dnet nor pypcap, no C compilation required. I work with following config Windows 10/Anaconda 3.5/latest WinPcap.
Minimum requirement to get Scapy running on Windows with Python 2.7 seems to be: pyreadline, pcapy, and dnet. The last two are the trickiest to compile and/or find pre-compiled binaries. One option for these is listed in the above answer. Another download, together with with detailed steps on how getting Scapy to run on Windows is at: https://github.com/zlorb/scapy. These steps describe also how to get the optional dependencies, such as Gnuplot and Tex.
RDFLib needs C extensions to be compiled to install on ActiveState Python 2.5; as far as I can tell, there's no binary installer anywhere obvious on the web. On attempting to install with python setup.py install, it produces the following message:
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
There are various resources on the web about configuring a compiler for distutils that discuss using MinGW, although I haven't got this to work yet. As an alternative I have VS2005.
Can anyone categorically tell me whether you can use the C compiler in VS2005 to build Python extension modules for a VS2003 compiled Python (in this case ActiveState Python 2.5). If this is possible, what configuration is needed?
The main problem is C run-time library. Python 2.4/2.5 linked against msvcr71.dll and therefore all C-extensions should be linked against this dll.
Another option is to use gcc (mingw) instead of VS2005, you can use it to compile python extensions only. There is decent installer that allows you to configure gcc as default compiler for your Python version:
http://www.develer.com/oss/GccWinBinaries
I can't tell you categorically, but I don't believe you can. I've only run into this problem in the inverse situation (Python built with VS2005, trying to build with VS2003). Searching the web did not turn up any way to hack around it. My eventual solution was to get VC Express, since VC2005 is when Microsoft started releasing the free editions. But that's obviously not an option for you.
I don't use ActiveState Python, but is there a newer version you could use? The source ships with project files for VS2008, and I'm pretty sure the python.org binary builds stopped using VS2003 a while ago.
As of today Mar 2012, I can categorically say it is possible with Python2.4.4 (only one I've tested) and Visual Studio 2005 and 2008. Just installing VS10 to check that. I don't know why it works and I have problems using distutils so I have to compile manually.