Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request help on pexpect
#1
Dear All,

Good Day. Please help / guide on how to get pexpect working, the following are the errors I am encountering. Appreciate if there is any reference guide provided on using pexpect. I am trying to write python code that is expected to run unix commands on several unix servers without having to manually enter userid/password on each server by using ssh (ssh -l user servername ; command etc). Thanks in advance.

[e025711@IBBFDPLSPW010 python]$ python3
Python 3.6.8 (default, Sep 26 2019, 11:57:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pexpect'
>>>
Reply
#2
I already tried installing pexpect, but it didn't help

[e025711@IBBFDPLSPW010 python]$ yum install pexpect
Loaded plugins: product-id, search-disabled-repos, subscription-manager
Skipping unreadable repository '/etc/yum.repos.d/rhel-dvd.repo'
You need to be root to perform this command.
[e025711@IBBFDPLSPW010 python]$ sudo su -
Last login: Sun Jul 19 12:00:01 HKT 2020
[root@IBBFDPLSPW010 ~]# yum install pexpect
Loaded plugins: product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Repository rhel-dvd is listed more than once in the configuration
rhel-dvd | 2.8 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package pexpect.noarch 0:2.3-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
pexpect noarch 2.3-11.el7 rhel-dvd 142 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 142 k
Installed size: 784 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pexpect-2.3-11.el7.noarch 1/1
Verifying : pexpect-2.3-11.el7.noarch 1/1

Installed:
pexpect.noarch 0:2.3-11.el7

Complete!
[root@IBBFDPLSPW010 ~]# ls
anaconda-ks.cfg
[root@IBBFDPLSPW010 ~]# python3
Python 3.6.8 (default, Sep 26 2019, 11:57:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pexpect'
>>> import pexpect.noarch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pexpect'
>>>

Installed pexpect is successfully imported in python2 but not in python3, How can I get it working on python3?

[root@IBBFDPLSPW010 ~]# python3
Python 3.6.8 (default, Sep 26 2019, 11:57:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pexpect'
>>> import pexpect.noarch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pexpect'
>>> quit()
[root@IBBFDPLSPW010 ~]# python2
Python 2.7.5 (default, Sep 26 2019, 13:23:47)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
>>>
Reply
#3
When you do yum install pexpect it will install to Python 2.
When you type python3 it start Python 3.6.8.
So should use pip to install pexpect.
python3 -m pip install --user pexpect
Also try pip3 -V command this should point to Python 3.6.
May need to install it.
python3.6 -m ensurepip
 
# Or a repository that has it
yum install --assumeyes python3-pip
Now test with pip3 -V and it should point to 3.6.
Example.
pip3 -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)
Then install to 3.6 would be.
pip3 install --user pexpect
Reply
#4
(Jul-19-2020, 08:51 AM)snippsat Wrote: When you do yum install pexpect it will install to Python 2.
When you type python3 it start Python 3.6.8.
So should use pip to install pexpect.
python3 -m pip install --user pexpect
Also try pip3 -V command this should point to Python 3.6.
May need to install it.
python3.6 -m ensurepip
 
# Or a repository that has it
yum install --assumeyes python3-pip
Now test with pip3 -V and it should point to 3.6.
Example.
pip3 -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip-18.0-py3.6.egg/pip (python 3.6)
Then install to 3.6 would be.
pip3 install --user pexpect


The server isn't connected to Internet, I mounted RHEL 7.8 DVD and using it as a repository. Received the following errors:

[root@IBBFDPLSPW010 ~]# python3 -m pip install --user pexpect
WARNING: Running pip install with root privileges is generally not a good idea. Try __main__.py install --user instead.
Collecting pexpect
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fceb21ab9e8>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fceb21ab0b8>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fceb21ab400>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fceb21abc18>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fceb21aba90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Could not find a version that satisfies the requirement pexpect (from versions: )
No matching distribution found for pexpect
[root@IBBFDPLSPW010 ~]# echo $?
1
[root@IBBFDPLSPW010 ~]# python3.6 -m ensurepip
WARNING: Running pip install with root privileges is generally not a good idea. Try __main__.py install --user instead.
Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages
Requirement already satisfied: pip in /usr/lib/python3.6/site-packages
[root@IBBFDPLSPW010 ~]# yum install --assumeyes python3-pip
Loaded plugins: product-id, search-
: disabled-repos,
: subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

rhel-dvd | 2.8 kB 00:00
Package python3-pip-9.0.3-5.el7.noarch already installed and latest version
Nothing to do
[root@IBBFDPLSPW010 ~]#
[root@IBBFDPLSPW010 ~]# pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
[root@IBBFDPLSPW010 ~]# pip3 install --user pexpect
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead.
Collecting pexpect
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb1455d68>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb1455320>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb1455668>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb14552b0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fefb14554e0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pexpect/
Could not find a version that satisfies the requirement pexpect (from versions: )
No matching distribution found for pexpect
[root@IBBFDPLSPW010 ~]#
Reply
#5
(Jul-19-2020, 02:19 PM)rsurathu Wrote: The server isn't connected to Interne
Try download wheel from a other Pc,then move it over and then try to install with pip.
pip3 install --user pexpect-4.8.0-py2.py3-none-any.whl 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,144 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Use pexpect to send user input alisha17 0 1,826 May-10-2022, 02:44 AM
Last Post: alisha17
  Not able to read the text using pexpect/expect Bipinjohnson 7 3,937 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  Sudden Problem with pexpect gw1500se 3 2,321 Nov-19-2021, 11:21 PM
Last Post: bowlofred
  How to use pexpect in python? tiho_bg 1 1,487 Oct-30-2021, 02:50 PM
Last Post: Yoriz
  how can I correct the Bad Request error on my curl request tomtom 8 4,964 Oct-03-2021, 06:32 AM
Last Post: tomtom
  Pexpect timesout before executing whole output eagerissac 0 1,450 Jun-23-2021, 03:30 AM
Last Post: eagerissac
  pexpect startup help korenron 2 3,428 Apr-27-2021, 07:23 AM
Last Post: korenron
  Problem with pexpect.exception.TimeOUT korenron 0 3,240 Apr-12-2021, 03:25 PM
Last Post: korenron
  SIGWINCH ignored when trying to start a screen with the pexpect module StatTark 0 1,791 Jul-06-2020, 10:12 AM
Last Post: StatTark

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020