Running Electrum in Python from the CLI on Ubuntu 20

  • Context: Python 
  • Thread starter Thread starter jack action
  • Start date Start date
  • Tags Tags
    Python Running Ubuntu
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
Messages
3,641
Reaction score
10,062
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.
 
Physics 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   Reactions: jack action