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
Click For Summary
SUMMARY

This discussion addresses issues encountered when running Electrum version 4.0.9 from the command line on Ubuntu 20, particularly regarding a circular import error caused by a local 'logging.py' file in the Electrum directory. The user must invoke the command with 'python3 electrum' instead of executing it directly, as the directory containing the Electrum executable is not on the system PATH. The problem arises because Python prioritizes local files over standard library modules, leading to conflicts. The older version 4.0.4 does not have this issue, as it lacks the local 'logging.py' file.

PREREQUISITES
  • Familiarity with Python 3.8 and its module import system
  • Understanding of command line operations in Ubuntu 20
  • Basic knowledge of file permissions and executable scripts
  • Experience with Python virtual environments (optional but beneficial)
NEXT STEPS
  • Learn how to modify the system PATH variable in Ubuntu to include custom directories
  • Investigate Python module import precedence and how to resolve circular import issues
  • Explore creating aliases in the shell for easier command execution
  • Review the differences between Electrum versions 4.0.4 and 4.0.9 to identify changes affecting functionality
USEFUL FOR

Python developers, system administrators, and users troubleshooting Electrum installation issues on Ubuntu.

jack action
Science Advisor
Insights Author
Messages
3,564
Reaction score
9,976
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   Reactions: jack action
Got it, I created an alias on the first computer.

Now I have other problems, but at least I'm going further.
 

Similar threads

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