Python cross-platform portable script - python-3.x

I am working on a web scraper in Pycharm. The project consists of around 5 python files and 8 dependencies. I have a virtual env setup in the IDE. How do I package the files and dependencies so they can be saved on any platform and executed from the command line? I looked into Pyinstaller, but it looks like Pyinstaller only creates executables for the OS it is running on. So I would need to create 2 executables for windows and linux. And, I am not necessarily looking for an executable, just need to be able package it so anyone can download it and run it easily.

Related

How to run GTK3 Python3 script outside of MSYS2 in Windows

How can I make my GTK3+ Python script work outside of Msys2's own Python interpreter, into my own venv (virtual environment) Python3 interpreter? I want to prepare my Python 3 script for distribution to other computers, but without Msys2.
I'm using Windows 10.
I've successfully followed the instructions on GTK's website, to download GTK3+ and the Python bindings, in Windows.
I've installed GTK3+ and the Python bindings using MSYS2. My script runs successfully within MSYS2's Python3 interpreter in C:\msys64\mingw64\bin. However, I want to run my Python script outside of MSYS2, with a separate Python 3 interpreter (venv) - not the one in MSYS2.
From my research, it seems that I need to copy the GTK3 .dll files and icons from
C:\msys64\mingw64\bin
and C:\msys64\mingw64\share
to the Python3 interpreter path that I want, with my script files in there too.
But when I attempt to run my script in the virtual environment, I get:
builtins.ImportError: cannot import name '_gi' from 'gi'
Any ideas? Thanks.
I don't know if that is possible.
But if the final intent is to distribute your app, then you should install PyInstaller inside MSYS2 and generate an executable there. Then you'll be able to distribute and execute your app on any Windows machine.
It will only be possible to run your program using the MSYS2 Python interpreter and with all of the required libraries. You can't just copy files and then run them with the Windows Python interpreter that was built using MSVC.
PyInstaller is a good solution to package an app with the interpreter and all of the libraries. The issue you mentioned about getting errors about no module named '_struct' has been fixed.

Installing Python silently

I have my code written in python 3.6.5. I am trying make this an installable package (something like install shield) and wanted to bundle python software also along with this installshield. OS is Windows
Will python work by unzipping the installation directory and then setting path variable?
When I use /quiet for silent installation of python, I could not change the path of installation directory to my choice, say in my case C:\test(even after setting TargetDir=C:\test). Where am I going wrong?
If there any other approach to bundle installation of python along with installation package can someone let me know?
Why not use Pyinstaller? If python is set to path you can run from CMD pip install pyinstaller. Then you can create a standalone exe that will include the python packages to run. Hold shift and open a CMD where your script is and then run a command similar to this
pyinstaller --noconsole --icon=data.ico --version-file=Version.txt -F LineQuery.py
The -F is the standalone package. Be aware though that you need to copy the DLLs from microsoft runtime visual c++ 2015 into the python DLL folder usually located at C:\Users\"user"\AppData\Local\Programs\Python\Python36\DLLs. That is if you package it on windows 10. Otherwise you'll have issues with your program running on earlier versions of windows.
The standalone package will be slow at startup. You can package it into a folder that will be faster. Just remove the -F

Compile python 3 script to standalone exe in Linux

Can a python 3 script be compiled in a linux environment in such a way as it can be run under Windows?
If so what compile tool? ie. py2exe or pyinstaller ect.
You're looking for cross-compilation, and the answer is no.
Can I package Windows binaries while running under Linux?
No, this is not supported. Please use Wine for this, PyInstaller runs fine in Wine. You may also want to have a look at this thread in the mailinglist. In version 1.4 we had build in some support for this, but it showed to work only half. It would require some Windows system on another partition and would only work for pure Python programs. As soon as you want a decent GUI (gtk, qt, wx), you would need to install Windows libraries anyhow. So it's much easier to just use Wine.
Can I package Windows binaries while running under OS X?
No, this is not supported. Please try Wine for this.
Can I package OS X binaries while running under Linux?
This is currently not possible at all. Sorry! If you want to help out, you are very welcome.
You may use Wine or the Windows Subsystem for Linux to attempt using PyInstaller to build stand-alone binaries for different operating systems, however, neither PyInstaller, nor Py2Exe, nor cx_freeze, nor any tool to my knowledge does this.
Effectively, in-order to do something like this, you would need a cross-compiler such as MinGW or VC++ for Linux, and integrate it into PyInstaller, which is very far outside of the scope of the project. It is much easier to use WINE or having a dual-boot system or multiple development computers.

Run python on Linux without python installed

Currently I'm using cx_Freeze to turn .py into .exe and this works fine with modules and everything, but I can't find any way to make it so it could run in Linux.
Is there any alternative for making it be able to run on Linux? Using something else other than cx_Freeze is fine.
Is there any way to compile it for Linux, while on Windows
From the docs
cx_Freeze works on Windows, Mac and Linux, but on each platform it only makes an executable that runs on that platform. So if you want to freeze your program for Windows, freeze it on Windows; if you want to run it on Macs, freeze it on a Mac.
You should try pyinstaller.
It supports creation of self-encapsulated python executables that work even when the python runtime is not installed.

Cross-compile Python in Ubuntu to run on Windows

I need to compile a python script for a project. I am programming it in my Linux(Ubuntu) environment, and I need to have the finalized product be a .exe file to run on windows.
--It needs to be compiled so that the windows machine receiving it doesn't need to have a python environment installed on it.--
I know pyinstaller can compile scripts into executables, but it doesn't do cross-compiling.
An older version of pyinstaller does, but it only supports python2.6
The problem is, I need python 2.7 or 3.+ for my project.
Is there a program I can use to accomplish this, or maybe a workaround... something?

Resources