{"id":368,"library":"ptyprocess","title":"ptyprocess","description":"A library to run subprocesses in a pseudo terminal, version 0.7.0. It is actively maintained with a release cadence focused on improvements and CI updates.","status":"active","version":"0.7.0","language":"python","source_language":"en","source_url":"https://github.com/pexpect/ptyprocess","tags":["subprocess","pseudo-terminal","python"],"install":[{"cmd":"pip install ptyprocess","lang":"bash","label":"Install ptyprocess"}],"dependencies":[],"imports":[{"note":"Common mistake is to use 'import ptyprocess' instead, which doesn't expose the PTYProcess class directly.","symbol":"PTYProcess","correct":"from ptyprocess import PTYProcess"}],"quickstart":{"code":"import os\nfrom ptyprocess import PTYProcess\n\nproc = PTYProcess.spawn(['ls', '-l'])\nprint(proc.read())","lang":"python","description":"This quickstart launches a subprocess to list files in the current directory."},"warnings":[{"fix":"Test subprocess compatibility before production use.","message":"Not all subprocesses behave the same in a pseudo terminal.","severity":"gotcha","affected_versions":"0.7.0"},{"fix":"Update your method calls to the new standardized approach.","message":"Older methods of invoking processes may not fully utilize the pty.","severity":"deprecated","affected_versions":"< 0.6.0"},{"fix":"Update your import statement from `from ptyprocess import PTYProcess` to `from ptyprocess.ptyprocess import PTYProcess`, or consult the library's documentation for the correct import path for your version.","message":"The `PTYProcess` class has been moved or removed from the top-level `ptyprocess` package, resulting in an ImportError.","severity":"breaking","affected_versions":"> 0.5.0"},{"fix":"Update your code to import 'PtyProcess' instead of 'PTYProcess'.","message":"The main class 'PTYProcess' has been renamed to 'PtyProcess'. Attempting to import 'PTYProcess' will result in an ImportError.","severity":"breaking","affected_versions":">= 0.7.0"}],"env_vars":null,"last_verified":"2026-05-12T13:19:57.171Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install ptyprocess` or `python -m pip install ptyprocess`. If using a virtual environment, ensure it's activated before installation.","cause":"The 'ptyprocess' library is not installed in the current Python environment or the Python interpreter being used cannot find it.","error":"ModuleNotFoundError: No module named 'ptyprocess'"},{"fix":"This is a system-level issue. You might need to close other terminal sessions, reboot the system, or increase the system's `kernel.pty.max` limit (e.g., by modifying `/etc/sysctl.conf` and applying with `sysctl -p`).","cause":"The operating system has reached its limit for the number of available pseudo-terminal (pty) devices.","error":"OSError: out of pty devices"},{"fix":"Ensure that `ptyprocess.PtyProcess.close()` is called correctly and that no other part of the code or other processes are managing the child process's lifecycle (e.g., calling `os.waitpid`) concurrently. When using `pexpect` (which uses `ptyprocess`), handle termination gracefully, possibly by checking `isalive()` before attempting to close if the child process might exit independently.","cause":"This error occurs when `ptyprocess` fails to terminate the child process it spawned, often because the child process is no longer running or `waitpid()` was called by another part of the program.","error":"ptyprocess.PtyProcessError: Could not terminate the child."},{"fix":"Check and adjust file permissions for `/dev/pts/ptmx` (e.g., `sudo chmod 666 /dev/pts/ptmx`). Ensure that `devpts` is correctly mounted.","cause":"The user or process running the application does not have the necessary permissions to create or open pseudo-terminal devices, often related to the `/dev/pts` file system.","error":"Failed to open PTY: Permission denied"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}