Python Running Electrum in Python from the CLI on Ubuntu 20

Click For Summary
Running Electrum on Ubuntu 20 presents challenges when using different versions of the software. On one computer with Electrum version 4.0.4, the executable runs directly from the command line. However, on another computer with version 4.0.9, the user must invoke Python explicitly by typing "python3 electrum" to execute it. This issue is compounded by a backtrace error indicating a circular import problem due to a local 'logging.py' file in the Electrum directory, which takes precedence over the standard library's logging module. The discussion highlights that Python prioritizes local files for imports, leading to this conflict. The older version of Electrum likely does not include a 'logging.py' file, allowing the standard library module to be used without issues. An alias was created on the first computer to streamline the process, but additional problems remain.
jack action
Science Advisor
Insights Author
Messages
3,551
Reaction score
9,896
I'm trying to run electrum (written in python) from the command line on Ubuntu 20. I have 2 similar computers. The first one has version 4.0.4 and once in the electrum folder, I type electrum (the name of the executable file) and it executes whatever command I ask for.

My problem is with my other computer - which has the latest version 4.0.9 - where, first odd problem, I have to type python3 electrum to get a response. I even changed the header of the file from #!/usr/bin/env python3 to #!/usr/bin/python3, still need to call python3 first (and the file is executable).

But the worst part is that it fails to run. I get this backtrace:

Code:
  File "electrum", line 39, in <module>
    import asyncio
  File "/usr/lib/python3.8/asyncio/__init__.py", line 8, in <module>
    from .base_events import *
  File "/usr/lib/python3.8/asyncio/base_events.py", line 18, in <module>
    import concurrent.futures
  File "/usr/lib/python3.8/concurrent/futures/__init__.py", line 8, in <module>
    from concurrent.futures._base import (FIRST_COMPLETED,
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 7, in <module>
    import logging
  File "/root/Electrum-4.0.9/electrum/logging.py", line 15, in <module>
    class LogFormatterForFiles(logging.Formatter):
AttributeError: partially initialized module 'logging' has no attribute 'Formatter' (most likely due to a circular import)

I know what happen, but I don't understand why. (I'm a newbie with python) In the electrum folder there is a 'logging.py' and the import logging is clearly referring to a file in the 'python3.8' folder, but it chooses the local one instead (hence the circular import problem). I don't know what to do with that (specifiying a folder?), especially since it works fine on the other machine.

I'm tired and I would gladly accept any help.
 
Technology news on Phys.org
jack action said:
I have to type python3 electrum to get a response.

If the directory containing the electrum file is not on your PATH, the shell won't be able to find it, even if it is marked as executable.

jack action said:
In the electrum folder there is a 'logging.py'

And Python always looks there first (i.e., in the directory where the script being executed is located) for a file to import, before any other location. That's why that file is getting imported instead of the Python standard library one.

jack action said:
it works fine on the other machine

Since you are running an older version of electrum on the other machine, my guess would be that that older version does not have a logging.py file in the electrum directory, so the Python standard library logging module gets imported.
 
  • Like
Likes jack action
Got it, I created an alias on the first computer.

Now I have other problems, but at least I'm going further.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
7
Views
2K