Create exe on linux

How to generate an executable on Linux for Windows? #2613

Comments

Drakota commented May 18, 2017

I’m trying to generate an executable from Linux for Windows.

pyinstaller —onefile —windowed montecarlo.py
I run this command and get a single executable that works on Linux just fine, I can open it and use my program, but if I try on Windows, it’s just a simple file. On Linux it’s a executable (application/x-executable), but on Windows it’s a Type of file: File Why?

The text was updated successfully, but these errors were encountered:

ghost commented May 18, 2017

Come back when you’ve completed CS50.

Drakota commented May 18, 2017

Why this arrogant response? The file created on Linux is executable, but if I copy it to Windows it’s just a File changing the file extension to .exe doesn’t work.

ghost commented May 18, 2017 •

Well, let me just copy and paste what wikipedia says:

Binary compatible operating systems are OSes that aim to implement binary compatibility with another OS, or another variant of the same brand. This means that they are ABI-compatible (for application binary interface). As the job of an OS is to run programs, the instruction set architectures running the OSes have to be the same or compatible. Otherwise, programs can be employed within a CPU emulator or a faster dynamic translation mechanism to make them compatible.

For example, the Linux kernel is not compatible with Windows. This does not mean that Linux can’t be binary compatible with Windows applications. Additional software, Wine, is available that does that to some degree. The ReactOS OS development effort, seeks to create an open source, free software OS that is binary compatible with Microsoft’s Windows NT family of OSes using Wine for application compatibility and reimplementing the Windows kernel for additional compatibility such as for drivers whereas Linux would use Linux drivers not Windows drivers. FreeBSD and other members of the BSD family have binary compatibility with the Linux kernel in usermode by translating Linux system calls into BSD ones. This enables the application and libraries code that run on Linux-based OSes to be run on BSD as well.

Note that a binary compatible OS is different from running an alternative OS through virtualization or emulation, which is done to run software within the alternative OS in the case when the host OS isn’t compatible. Sometimes virtualization is provided with the host OS (or such software can be obtained), which effectively makes the host OS compatible with programs. For example, Windows XP Mode for Windows 7 allows users to run a 64-bit version of Windows 7 and enable old software to still work in a 32-bit virtual machine running Windows XP; VMware Workstation/VMware Fusion, Parallels Workstation, and Windows Virtual PC allow other OSes to be run on Windows, Linux, and OS X.

For another example, Mac OS X on the PowerPC had the ability to run Mac OS 9 and earlier application software through Classic—but this did not make OS X a binary compatible OS with Mac OS 9. Instead, the Classic environment was actually running Mac OS 9.1 in a virtual machine, running as a normal process inside of OS X.[1][2]

ghost commented May 18, 2017

Or I could copy from the PyInstaller manual:

PyInstaller is tested against Windows, Mac OS X, and Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a Linux app you run it in Linux, etc. PyInstaller has been used successfully with AIX, Solaris, and FreeBSD, but is not tested against them.

ghost commented May 18, 2017 •

Also, please do close this issue so as not to waste others’ time.

Читайте также:  Windows registry internet explorer version

virtuald commented May 18, 2017

@xoviat that was a bit much. Simply copy/pasting the piece from the pyinstaller manual would have been sufficient. We were all new to this once.

Источник

Кросс-упаковка python кода в exe файл из Linux c помощью PyInstaller

Рано или поздно перед Python программистом встает проблема распространения своего ПО на компьютерах без установленного интерпретатора Python. Наиболее рациональным способом при этом кажется упаковка кода в автономный бинарный файл. Для этого существует целый сомн фреймворков.

По прочтении обсуждений в разных местах, пришел к выводу, что PyInstaller лучше всего подходит для данных целей из-за простоты в использовании, своей кросс-платформенности и потому, что собранный им exe-файл легче переносится с одной версии Windows на другую. А так же позволяет без особых танцев собирать бинарники для Windows из-под других операционных систем.

Подготовка

Нам понадобятся:

  • Python2 — К сожалению PyInstaller работает только для Python-2.x.x
  • Сам Pyinstaller

Pywin32 — дополнения Python для Windows. Опять же последняя стабильная версия (216)
Wine — ну без него тут никуда.

Я тестировал кросс-сборку на Ubuntu 11.04 с Python 2.7.1 и Wine 1.3.20.

Ставим все необходимое:

#Wine
sudo apt-get install wine1.3-dev
#Python
wget http://python.org/ftp/python/2.7.1/python-2.7.1.msi
wine msiexec /i python-2.7.1.msi

#Pyinstaller
wget http://www.pyinstaller.org/static/source/1.5/pyinstaller-1.5.tar.bz2
tar xvf pyinstaller-1.5.tar.bz2

#Pywin32
wget http://downloads.sourceforge.net/project/pywin32/pywin32/Build216/pywin32-216.win32-py2.7.exe?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpywin32%2Ffiles%2Fpywin32%2FBuild216%2F&ts=1305544745&use_mirror=citylan -o pywin32.exe
wine pywin32.exe

Настройка и запуск

Теперь необходимо настроить Pyinstaller с помощью скрипта Configure.py. Конфигурацию надо производить каждый раз когда меняется конфигурация Python, поэтому имеет смысл держать отдельную версию Pyinstaller для каждой версии Python. Сконфигурируем Pyinstaller под Windows-версию интерпретатора:

cd pyinstaller-1.5
wine

Теперь можно собирать exe-файл. Сначала создаем spec-файл, в котором содержаться настройки упаковки проекта. Для наглядности назовем упаковываемый файл test.py (в случае, когда в проекте не один файл, указываем путь к главному).

/.wine/drive_c/Python27.exe Makespec.py test.py

По умолчанию папка со spec-фалом будет создана в папке Pyinstaller и будет иметь имя упаковываемого файла без расширения (в нашем случае test).

К команде создания spec-файла можно добавить полезные ключи, например:

  • —onefile — по умолчанию PyInstaller создает exe-файл и кладет в папку рядом с ним необходимые dll. Этот ключ форсирует упаковку всего в единый бинарник.
  • —out=DIR — позволяет задать определенную папку для spec-файла
  • —windowed — под Windows отключает консоль приложения

И наконец финальный этап — построение:

/.wine/drive_c/Python27/python.exe Build.py test/test.spec

Упакованное приложение можно найти в папке dist/ внутри папки со spec-файлом.

За сим все. Тестовая программа заработала под Wine, а затем под Windows XP и Windows 7 без малейших писков.

Источник

How to Install and Run EXE Files in Linux Environment

Install and run EXE files in Linux environment is very much necessary sometimes. There are few much-needed Windows applications, which require to be installed in Linux and run the exe file on Linux or Ubuntu OS. I am a Ubuntu user, the OS runs in Linux kernel and I am curious to know: “can Linux run exe?”. I need some Windows software occasionally to run in my PC. It is not always possible to shift the OS for running a specific Windows software. Either, you need to boot Windows from a dual booting computer, otherwise you want a separate PC (that has a Windows OS). The best thing is if you, anyhow, manage to install the Windows software or exe files and run it inside Linux or Ubuntu OS.

If you are new at Linux OS and don’t know much about it, then let me define Linux OS at first.

The Linux OS is open source, free distributed and cross-platform operating system which runs on Unix base. Linux can be installed easily on a PC, laptop, mobile, tablet, sever, super computer, video game console (supports low end to high end configuration) etc. Moreover, the operating system is much more secure and light-weight than any other popular OS like Windows, Mac and so on.

Linux mainly uses the ext4 file system; the file format is completely different than the executable file system i.e. .exe file. EXE files are used in Windows OS. So, basically it is hard to use an exe file in Linux architecture. But, using different software like WineHQ, PlayOnLinux, etc. in your Linux operating system, one can easily install and run different favorite Windows software on Linux OS.

Читайте также:  Как отключить управление питанием windows

How to Open, Run or Install Exe Files on Linux Ubuntu Using ‘Wine’

Do you know the answer of the question: “Can Linux run exe?”. To run exe files on Linux you need to install ‘Wine’ on Linux or on Ubuntu. ‘Wine’ is an open source Linux based free program that allows any Linux version (Ubuntu, Linux Mint) users to install and run Windows applications. Wine is very much useful for programmers and developers (with a software library WineLib) to compile, modify any Windows application in Unix environment.

Download and Install Wine:

You need to download the specific version of Wine from the official website WineHQ (https://www.winehq.org/). In the download page, you will get all the major wine versions of Linux. Select the Linux version (among all the versions of Linux like Ubuntu, Red Hat, etc.) you are using and download the Wine program. If you are unable to find the exact version of the OS, then try to find the related version from the list that is the base version (for example, Debian is the base version of Linux Mint). Related version of Wine should work on your Linux PC. Click on the preferred link and click on on-screen installation instruction. After you download the Wine software from the link, right click on the icon of the program, select install option and follow the steps. After successful installation of Wine apps, it will create a new folder (.wine) at the home/user-name (user name must be the user name given by you at the time of user profile creation) directory.
Initially, .wine folder will be invisible to you unless you press the Ctrl+H together to show hidden files. Then open .wine folder and navigate to the path ../.wine/drive_C/Program Files . The full path will be:

This is your program files folder where you can put Windows apps and install it to Linux. In the next step, you have to download .exe file and move the file to program files folder. Then right-click on that file and select open with option. Choose Wine windows program loader to install and run the Windows application in Linux.

Linux Ubuntu 10.04 and later version users can install Wine on their Linux system direct from the ‘Ubuntu Software Center’. Method is as follows:

  • Open Applications and navigate to Software Center.
  • In the search bar, enter ‘Wine’ and press Enter to search for that.
  • Click on Install button of Wine that you get from the search list.
  • It will create a virtual C:\ drive on your Ubuntu automatically.
  • Now you can open .exe files and install them in virtual c:\ drive of your Linux system.

Older versions and other versions users should follow these steps to add Wine to Linux:

  • Navigate to System >> Administration >> Software Sources.
  • Select the other software section and select Add button.
  • Then to install the Wine program in Linux, add the following line in the terminal box: ppa:ubuntu-wine/ppa
  • Alternatively, you can use the command from the terminal to install add Wine:

Every Linux version follows separate installation procedure. But there is a common method to install Wine program to any Linux OS. You need to run a command at the Linux terminal to install Wine.

You must have an active internet connection and super user permission (root access) to add Wine to Linux. A Ubuntu user can use Alt+F2 shortcut to open run box, type “gnome-terminal” and press Enter to open the terminal. Type su to change your access to root access. You will be asked for Administrative or root password and then run the commands.

Steps to Install Wine on Linux Ubuntu:

Ubuntu is the most popular version of Linux environment. Here I mention the steps to install Wine in Ubuntu 19.10. For different version of the Ubuntu, the mentioned command needs some modifications which I also mention in the detail below.

  1. Press and hold Ctrl+Alt+T together to open up the Terminal window in Ubuntu.
  2. Enter the following terminal command to enable 32-bit support. Account password is mandatory in this step.
  3. To add and install Wine repository key, enter the following command to add support:
  4. Now, execute the mentioned command to add the Wine repository only in Ubuntu 19.10:
  5. Use the modified command to add the Wine repository for Ubuntu 18.04 and Linux Mint 19.x:
  6. Use the command to add the Wine repository in Ubuntu 16.04 and Linux Mint 18.x:
  7. libfaudio0 is very much required to use WineHQ and use the following command to add it.
  8. That’s all. Now, your Ubuntu OS is ready to run Windows files/.exe files.
Читайте также:  Unidentified network windows 10 как исправить

How to Run and Install Exe File on Linux or Ubuntu:

Method#1: In the above section, I have already mentioned the process of installing a Windows program on a Linux OS. However, if the method does not work, you can use the command method to open and run exe file. The command should be something like this:

A Linux Mint user can use the command for the same purpose:

Note: Replace the ‘app-setup-file-name’ with actual the setup file name.
Before doing that change the directory location to that folder, exactly where the setup file is located. For example, if you keep the exe set-up file to desktop, then before run the above command, you need to run another command i.e.

Otherwise, by navigating Applications >> Wine >> Programs and from the program’s list, you can run the exe program in your Linux PC.

Method #2 (Alternative method):

  • After performing the above mentioned steps to install WineHQ on your Linux PC, you need to restart the computer and make sure that the WineHQ is installed correctly to your PC.
  • Now, download the Windows executable file i.e. .exe file on your Linux computer.
  • Right click on the file and select Wine Windows Program Loader option from the right-click context menu. If the option is not available in the right-click context menu, try the Other option and find the Wine Windows Program Loader option there.
  • Wine might prompt for the installation of Wine Gecko and Wine Mono installers. Install them accordingly.
  • Now, you are ready to go through the Windows software installation wizard.
  • Finish the Windows .exe file/software installation process and run it on your Linux OS.

Note: Wine creates an environment to install and run windows applications in Linux. But, sometime Wine fails to run some applications. In that case, you can give a try with PlayOnLinux to run those programs.

Install Windows Apps on Linux Ubuntu Using ‘PlayOnLinux’

Like ‘Wine’, PlayOnLinux provides a compatibility layer which allows Linux users to install Windows-based software and exe files. A Linux novice user gets in trouble while installing Wine. However, PlayOnLinux is very easy to install. It has the identical functionality just like Wine. Apart from it, the software supports a wide variety of applications. You may call it the graphical front end tool of Wine which provides a very simple solution for installing Windows OS.

PlayOnLinux supports popular Windows applications like Adobe Photoshop, Safari Browser, MS Office etc. The company fixes all the bugs and gives uses a smooth experience with Windows software, applications and .exe files installation. It also supports modern games and patches as well.

You can download the PlayOnLinux from the following link:

To install the software use the following commands step wise:

A game-maniac can take help of Lutris to play some simple and strategic game on a Linux PC. Use the following command to install Lutris:

In this tutorial, I have described how to install and run exe files (Windows executable files) on a Linux computer (Ubuntu or Linux Mint PC). So far, Wine is the only program which allows Windows program to be installed on Linux. However, PlayOnLinux is the modern alternative that helps you installing .exe to Linux so that you can run your favorite Windows applications on your Linux OS.

Источник

Оцените статью