Friday, 22 November 2024

Installing Python Modules from inside Wine

 WINE is a virtual Windows environment that allow the Windows software to be run from inside a Linux OS.

It is useful when bundling a Python script into a Windows .exe executable file (as a single application).

Although a Python programming environment, for example Anaconda and Spyder, are installed and operated from the Linux platform, to work with Python in Wine you must have a separate Python installation in place.

so, when you have created a Python application in Spyder (Linux), and you want to use wine to bundle it for a Windows application, you must make sure that the modules that the app calls on are also installed in the Windows environment.  Having them in the Linux install is not enough, as the two Pythons are independent of each other.

So:

  1. Open a new terminal
  2. type "wine" to enter the wine environment:
  3. pip should be installed as a part of the Python install.  There are now two commands that will use pip to install the missing module.  IUf, for example, you are installing tkinter, either:
                    i.     Type "wine python -m pip install tk"
                    ii.    Type  "pip install tk":
Note that in this instance, I have already installed Tkinter, hence the message "already satisfied".  ALSO note that despite making the query in Wine, it defaults to the LINUX distribution, NOT the Wine.  How do I know?  To install Python for a Windows environment, I downloaded the distribution direct from the Python site, and it sits as a .exe file:
        To install the Python package, you type:
wine (address)/python-3.12.4-amd64.exe    (or whatever the name of the distro file is):


The .exe gives the pop-up screen with install options.  Note that I have chosen to install a distro that is a bit older than the current one (3.13 at time of writing), as the pip module is a specific part of the installation.

Typing "wine python" will begin Python, and will show which distribution it is running - Linux or Windows.  Hence it is a good idea to have different versions, and if the first run gives you the Linux distro, enter "wine python" again.  The key to working within the Linux terminal is knowing that if you do not get the desired result the first time, try again.  And again.  Often the repeats give the right output.

If you are uncertain what modules are installed in Python within the Wine environment, you first type "python3" to enter the python module, and then type "help('modules') :

After the polite message, it collates and returns a listing of all modules in the Wine Python installation:

etc., scrolling on down through the terminal window.

No comments:

Post a Comment

Using Python to Write a Dataframe to a Google Spreadsheet

 I had all sort of issues with this one.  Multiple searches, and trying many variations of the Google API access code modules to find one th...