Tuesday, 4 February 2025

How to Fix Run Error "DisplayConnectionError: b'Authorization required, but no authorization protocol specified\n'"

 This is an error that is common on machines that are running a Linux OS, notably if you have had a break from developer work.

While my machine is running Linux, I use Spyder for my dev-ops environment, although the error will occur in other developer platforms.  Simply, when test-running a program, it fails to launch, and the log reports a "xlib error displayconnectionerror cant connect to display" error.

The issue is within neither the developer platform or your code, but in the supporting libraries within the Linux distribution of Python, and has an easy update fix.

Open a terminal window (CTRL-Alt-T), and enter the command

   xhost +

Let that run, and then enter the command

        sudo apt-get install python3-tk python3-dev

Close the terminal, re-open your developer platform, and run your code.


Wednesday, 8 January 2025

Installing New Modules Using Linux Terminal

 There is much that is said, and more that is assumed.


The Linux terminal can be opened by using the Ctrl-Alt-T shortcut.  From there, one could type "python" or, ideally, "python3" to enter the python environment within the terminal window.

It is not practical to install modules at this point.

You can type "help", and then "help(modules)" to get a complete listing of all modules that are currently installed in your machine's Python environment.  But you cannot install using pip.  It will error.

Close the terminal window and open a new terminal.

In this following example, I am wanting to install the Google api modules:

Look at the first command:


I dived straight in and used "python3" to invoke the "ensurepip" module to make things a little smoother.  NOTE that I did NOT enter the python environment - this is a command at the top, primary command level within the terminal.

same as for the second command:


This is the command as directed on the Google Quick Start page.  NOTE that as with using the "python3" command I used "pip3", NOT the traditional "pip" module. 

Note that the terminal goes into action instantly - making the connection, downloading and then installing the modules:


Downloaded and successfully installed.







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.

Tuesday, 19 November 2024

Use Pyinstaller inside Wine

 Pyinstaller is a tidy tool that will take your python code and wrap it with its dependencies and libraries into a single application file.

The trouble is that if you run it on Linux it will create a Linux app.  

If you want it to create a Windows .exe app, you must run Pyinstaller in a Windows environment.

So, we use Wine, which recreates a Windows environment within a Linux terminal.

As an example, I have a Python app sitting in a folder in my home directory, and I want to create a Windows .exe app for a client.  I have already installed Wine.

Steps:

1.    Ctrl-Alt-T to open a terminal window

2.    The command:  $ wine pyinstaller.exe --onefile /home/joel/Python_Programs/CARAT.py

wine                    starts the wine environment

pyinstaller.exe    runs the pyinstaller program within Python, within wine

--onefile              bundles the executable into one file

rest is the location of the .py file that is to be bundled.

Pyinstaller creates a couple of new folders within the home folder, and the .exe fill sits within the Dist folder:



 

 

       

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...