Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After chaning to python3.11 getting a import error #752

Closed
ayoubbenext opened this issue May 1, 2023 · 6 comments
Closed

After chaning to python3.11 getting a import error #752

ayoubbenext opened this issue May 1, 2023 · 6 comments

Comments

@ayoubbenext
Copy link

$HOME/.config/terminator/config
[global_config]
suppress_multiple_term_dialog = True
[keybindings]
[profiles]
[[default]]
[layouts]
[[default]]
[[[window0]]]
type = Window
parent = ""
[[[child1]]]
type = Terminal
parent = window0
[plugins]

Describe the bug
Getting a python import error.
Traceback (most recent call last):
File "/usr/bin/terminator", line 24, in
import psutil
File "/usr/lib/python3/dist-packages/psutil/init.py", line 102, in
from . import _pslinux as _psplatform
File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 26, in
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux' from partially initialized module 'psutil' (most likely due to a circular import) (/usr/lib/python3/dist-packages/psutil/init.py)

To Reproduce
Install python3.11.3

Expected behavior
Opening a terminator shell

Screenshots
image

Desktop (please complete the following information):

  • OS or Linux Distribution: Linux Ubuntu Jammy using WSL
  • Version 22.04 LTS
  • Display Technology: ?

Additional context
After changing to python3.11 this error occured.

nautics889 added a commit to nautics889/terminator that referenced this issue May 2, 2023
Removed unused imports in:
* terminator
* terminatorlib/plugins/dir_open.py
* terminatorlib/terminal.py
* terminatorlib/terminal_popup_menu.py
* terminatorlib/terminator.py
* tests/test_signalman.py
@nautics889
Copy link
Contributor

nautics889 commented May 2, 2023

Hello, @ayoubbenext.


I couldn't reproduce the error having the same environment:

  • Ubuntu 22.04 LTS Jammy (on top of WSL)
  • Python v3.11.3 (pyenv)
  • Terminator v2.1.3

Terminator was installed from source via pip.
Terminator launches correctly.


However, according to the screenshot you've attached, Terminator fails at 24 line in entry (main) module, when trying to import psutil. I'm pretty sure it's an error from psutil library, terminator just catched that.


Meanwhile, psutil was added a long time ago for getting ibus processes via psutil.process_iter(). There is definitely no usage for psutil in the current implementation (across main terminator module i mean).


I've uploaded PR with removing that import and some else unused import statements which have been present in Terminator's sources. I would suggest you to test, if this works out:

  1. Clone the PR:
$ git clone -b issue-752-remove-unused-imports https://github.com/nautics889/terminator.git && cd terminator

Alternatively you can use Github CLI:

$ gh pr checkout 753  # from the root repo directory
  1. Install terminator via pip. Make sure you use according python 3.11 interpreter (although I bet the exact version of python doesn't actually matter in our case.
$ pip install .  # from the root of the repo you've cloned
  1. Launch terminator:
$ terminator

If it's fails with something else, please let me know.


I'd also advise you to run python's REPL and try to import psutil:

$ python3
Python 3.11.3 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil

@ayoubbenext
Copy link
Author

Thanks for you're reply, getting the followin error when installing the pull request:
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error

× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [94 lines of output]
+ meson setup /tmp/pip-install-i7zvy_il/dbus-python_51ae22be3f384cccba948f812916a264 /tmp/pip-install-i7zvy_il/dbus-python_51ae22be3f384cccba948f812916a264/.mesonpy-tzl25c8f/build -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=/tmp/pip-install-i7zvy_il/dbus-python_51ae22be3f384cccba948f812916a264/.mesonpy-tzl25c8f/build/meson-python-native-file.ini
The Meson build system
Version: 1.1.0
Source dir: /tmp/pip-install-i7zvy_il/dbus-python_51ae22be3f384cccba948f812916a264
Build dir: /tmp/pip-install-i7zvy_il/dbus-python_51ae22be3f384cccba948f812916a264/.mesonpy-tzl25c8f/build
Build type: native build
Project name: dbus-python
Project version: 1.3.2
C compiler for the host machine: cc (gcc 11.3.0 "cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0")
C linker for the host machine: cc ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64
Compiler for C supports arguments -fno-common: YES
Compiler for C supports arguments -Wno-missing-field-initializers: YES
Compiler for C supports arguments -Wno-declaration-after-statement: YES
Compiler for C supports arguments -Wno-inline: YES
Compiler for C supports arguments -Wno-redundant-decls: YES
Compiler for C supports arguments -Wno-switch-default: YES
Compiler for C supports arguments -Wno-write-strings: YES
Compiler for C supports arguments -Wcast-align: YES
Compiler for C supports arguments -Wdouble-promotion: YES
Compiler for C supports arguments -Wduplicated-cond: YES
Compiler for C supports arguments -Wfloat-equal: YES
Compiler for C supports arguments -Wformat-nonliteral: YES
Compiler for C supports arguments -Wformat-security: YES
Compiler for C supports arguments -Wformat=2: YES
Compiler for C supports arguments -Winit-self: YES
Compiler for C supports arguments -Wlogical-op: YES
Compiler for C supports arguments -Wmissing-declarations: YES
Compiler for C supports arguments -Wmissing-format-attribute: YES
Compiler for C supports arguments -Wmissing-include-dirs: YES
Compiler for C supports arguments -Wmissing-noreturn: YES
Compiler for C supports arguments -Wnull-dereference: YES
Compiler for C supports arguments -Wpacked: YES
Compiler for C supports arguments -Wpointer-arith: YES
Compiler for C supports arguments -Wshadow: YES
Compiler for C supports arguments -Wswitch-enum: YES
Compiler for C supports arguments -Wundef: YES
Compiler for C supports arguments -Wunused-but-set-variable: YES
Compiler for C supports arguments -Wjump-misses-init: YES
Compiler for C supports arguments -Wmissing-prototypes: YES
Compiler for C supports arguments -Wnested-externs: YES
Compiler for C supports arguments -Wold-style-definition: YES
Compiler for C supports arguments -Wpointer-sign: YES
Compiler for C supports arguments -Wstrict-prototypes: YES
Configuring _dbus-python-config.h using configuration

  Executing subproject dbus-gmain

  dbus-gmain| Project name: dbus-gmain
  dbus-gmain| Project version: undefined
  dbus-gmain| C compiler for the host machine: cc (gcc 11.3.0 "cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0")
  dbus-gmain| C linker for the host machine: cc ld.bfd 2.38
  dbus-gmain| Compiler for C supports arguments -fno-common: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wno-missing-field-initializers: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wcast-align: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wdouble-promotion: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wduplicated-branches: YES
  dbus-gmain| Compiler for C supports arguments -Wduplicated-cond: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wfloat-equal: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wformat-nonliteral: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wformat-security: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wformat=2: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Winit-self: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wlogical-op: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wmissing-declarations: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wmissing-format-attribute: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wmissing-include-dirs: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wmissing-noreturn: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wnull-dereference: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wpacked: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wpointer-arith: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wredundant-decls: YES
  dbus-gmain| Compiler for C supports arguments -Wshadow: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wswitch-default: YES
  dbus-gmain| Compiler for C supports arguments -Wswitch-enum: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wundef: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wunused-but-set-variable: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wwrite-strings: YES
  dbus-gmain| Compiler for C supports arguments -Wdeclaration-after-statement: YES
  dbus-gmain| Compiler for C supports arguments -Wjump-misses-init: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wmissing-prototypes: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wnested-externs: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wold-style-definition: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wpointer-sign: YES (cached)
  dbus-gmain| Compiler for C supports arguments -Wstrict-prototypes: YES (cached)
  dbus-gmain| Found pkg-config: /usr/bin/pkg-config (0.29.2)
  dbus-gmain| Run-time dependency dbus-1 found: YES 1.12.20
  dbus-gmain| Found CMake: /usr/bin/cmake (3.22.1)
  dbus-gmain| Run-time dependency glib-2.0 found: NO (tried pkgconfig and cmake)

  ../../subprojects/dbus-gmain/meson.build:108:11: ERROR: Dependency "glib-2.0" not found, tried pkgconfig and cmake

  A full log can be found at /tmp/pip-install-i7zvy_il/dbus-python_51ae22be3f384cccba948f812916a264/.mesonpy-tzl25c8f/build/meson-logs/meson-log.txt
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

@mattrose
Copy link
Member

mattrose commented May 4, 2023

Meanwhile, psutil was added a long time ago for getting ibus processes via psutil.process_iter(). There is definitely no usage for psutil in the current implementation (across main terminator module i mean).

psutil is still used in the cwd code for determining the cwd of the Terminator process. According to my reading of the code, your PR will fail as soon as terminator tries to open a terminal

@mattrose
Copy link
Member

mattrose commented May 4, 2023

On a more general note, trying to "fix" terminator to work around bugs in other libraries and programs is a recipe for a lot of work for no return.

@ayoubbenext
Copy link
Author

So what's the solution? Still got:
ImportError: cannot import name '_psutil_linux' from partially initialized module 'psutil' (most likely due to a circular import) (/usr/lib/python3/dist-packages/psutil/init.py)

@mattrose
Copy link
Member

mattrose commented Jun 9, 2023

I'm not sure. Python 3.11 and psutil works fine for me

[mattrose@fedora ~]$ python --version
Python 3.11.2
[mattrose@fedora ~]$ terminator
[mattrose@fedora ~]$

Maybe try making sure that you''re running and using the system installed version of psutil. If you are, then try uninstalling it and reinstalling it?

@mattrose mattrose closed this as completed Jun 9, 2023
nautics889 added a commit to nautics889/terminator that referenced this issue Jan 26, 2024
Removed unused imports in:
* terminator
* terminatorlib/plugins/dir_open.py
* terminatorlib/terminal.py
* terminatorlib/terminal_popup_menu.py
* terminatorlib/terminator.py
* tests/test_signalman.py
mattrose added a commit that referenced this issue Feb 5, 2024
fix: Remove unused imports in several modules #752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants