My coworker and I have the exact same code, using the same libraries, but yet his code works and mine doesn't. We've gotten stuck trying to figure out what is wrong. Any help would be greatly appreciated. The code and error are below.
Code:
import os
os.environ.update({'MALLET_HOME':r'C:...\\mallet-2.0.8/'})
mallet_path = 'C:...\\mallet-2.0.8\\bin\\mallet'
ldamallet = gensim.models.wrappers.LdaMallet(mallet_path, corpus=corpus, num_topics=10, id2word=id2word)
Output and Error:
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-79-6122457c60e1> in <module>
----> 1 ldamallet = gensim.models.wrappers.LdaMallet(mallet_path, corpus=corpus, num_topics=10, id2word=id2word)
C:\ProgramData\Anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py in __init__(self, mallet_path, corpus, num_topics, alpha, id2word, workers, prefix, optimize_interval, iterations, topic_threshold, random_seed)
129 self.random_seed = random_seed
130 if corpus is not None:
--> 131 self.train(corpus)
132
133 def finferencer(self):
C:\ProgramData\Anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py in train(self, corpus)
270
271 """
--> 272 self.convert_input(corpus, infer=False)
273 cmd = self.mallet_path + ' train-topics --input %s --num-topics %s --alpha %s --optimize-interval %s '\
274 '--num-threads %s --output-state %s --output-doc-topics %s --output-topic-keys %s '\
C:\ProgramData\Anaconda3\lib\site-packages\gensim\models\wrappers\ldamallet.py in convert_input(self, corpus, infer, serialize_corpus)
259 cmd = cmd % (self.fcorpustxt(), self.fcorpusmallet())
260 logger.info("converting temporary corpus to MALLET format with %s", cmd)
--> 261 check_output(args=cmd, shell=True)
262
263 def train(self, corpus):
C:\ProgramData\Anaconda3\lib\site-packages\gensim\utils.py in check_output(stdout, *popenargs, **kwargs)
1916 error = subprocess.CalledProcessError(retcode, cmd)
1917 error.output = output
-> 1918 raise error
1919 return output
1920 except KeyboardInterrupt:
CalledProcessError: Command 'C:\mallet-2.0.8\bin\mallet import-file --preserve-case --keep-sequence --remove-stopwords --token-regex "\S+" --input C:\Users\CST~1.JEO\AppData\Local\Temp\84f7e0_corpus.txt --output C:\Users\CST~1.JEO\AppData\Local\Temp\84f7e0_corpus.mallet' returned non-zero exit status 1.
Related
01/23/23-10:07:16 :: adnodemgrctl.sh version 120.11.12020000.12
Calling txkChkEBSDependecies.pl to perform dependency checks for ALL MANAGED SERVERS
ERROR DESCRIPTION:
(FATAL ERROR
PROGRAM : /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl(/oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/bin/txkrun.pl)
TIME : Mon Jan 23 10:07:17 2023
FUNCTION: TXK::Process::run [ Level 3 ]
MESSAGES:
Command error: = 2304, = unzip -o /oracle/u02/VIS/fs2/inst/apps/VIS_vision/logs/appl/rgf/TXK/txkChkEBSDependecies_Mon_Jan_23_10_07_17_2023/formsapp.ear -d /oracle/u02/VIS/fs2/inst/apps/VIS_vision/logs/appl/rgf/TXK/txkChkEBSDependecies_Mon_Jan_23_10_07_17_2023
STACK TRACE
at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/Error.pm line 168
TXK::Error::abort('TXK::Error', 'HASH(0xd432e8)') called at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/Common.pm line 299
TXK::Common::doError('TXK::Process=HASH(0x19224d0)', 'Command error: = 2304, = unzip -o /oracle/u02/...', undef) called at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/Common.pm line 314
TXK::Common::setError('TXK::Process=HASH(0x19224d0)', 'Command error: = 2304, = unzip -o /oracle/u02/...') called at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/Process.pm line 449
TXK::Process::run('TXK::Process=HASH(0x19224d0)', 'HASH(0x1a22af0)') called at /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl line 1163
TXK::RunScript::unzipFile('/oracle/u02/VIS/fs2/inst/apps/VIS_vision/logs/appl/rgf/TXK/tx...', '/oracle/u02/VIS/fs2/inst/apps/VIS_vision/logs/appl/rgf/TXK/tx...') called at /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl line 815
TXK::RunScript::extractLatestFrmSrvJar() called at /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl line 1248
TXK::RunScript::checkFormsApp() called at /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl line 276
eval {...} called at /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl line 182
require /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txkChkEBSDependecies.pl called at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/RunScript.pm line 105
TXK::RunScript::require('TXK::RunScript', '/oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txk...') called at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/Script.pm line 177
eval {...} called at /oracle/u02/VIS/fs2/EBSapps/appl/au/12.0.0/perl/TXK/Script.pm line 177
TXK::Script::run('TXK::Script=HASH(0x139e460)', '/oracle/u02/VIS/fs2/inst/apps/VIS_vision/logs/appl/rgf/TXK', '/oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/patch/115/bin/txk...') called at /oracle/u02/VIS/fs2/EBSapps/appl/fnd/12.0.0/bin/txkrun.pl line 174
)
W A R N I N G *
Error while executing the perl script txkChkEBSDependecies.pl
We have determined that one or more checks failed for MANAGED SERVERS.
Please check logs for more details.
Validated the passed arguments for the option ebs-get-nmstatus
Connecting to Node Manager ...
Successfully Connected to Node Manager.
The Node Manager is up.
NodeManager log is located at /oracle/u02/VIS/fs2/FMW_Home/wlserver_10.3/common/nodemanager/nmHome1
01/23/23-10:07:21 :: adnodemgrctl.sh: exiting with status 2
CAN ANY ONE HELP ME WITH THIS PROBLEM ?
my problem started when I tried to use conda create -n nam python3 and got conda.exceptions.CondaRuntimeError:
The following packages will be downloaded:
package | build
---------------------------|-----------------
vs2015_runtime-14.0.25420 | 0 2.0 MB
vc-14 | 0 703 B
python-3.6.2 | 0 31.5 MB
certifi-2016.2.28 | py36_0 214 KB
wheel-0.29.0 | py36_0 129 KB
wincertstore-0.2 | py36_0 14 KB
setuptools-36.4.0 | py36_1 534 KB
pip-9.0.1 | py36_1 1.7 MB
------------------------------------------------------------
Total: 36.0 MB
The following NEW packages will be INSTALLED:
certifi: 2016.2.28-py36_0
pip: 9.0.1-py36_1
python: 3.6.2-0
setuptools: 36.4.0-py36_1
vc: 14-0
vs2015_runtime: 14.0.25420-0
wheel: 0.29.0-py36_0
wincertstore: 0.2-py36_0
Proceed ([y]/n)?
Fetching packages ...
vs2015_runtime 100% |###############################| Time: 0:00:00 3.63 MB/s
vc-14-0.tar.bz 100% |###############################| Time: 0:00:00 140.66 kB/s
python-3.6.2-0 100% |###############################| Time: 0:00:05 5.56 MB/s
certifi-2016.2 100% |###############################| Time: 0:00:00 1.18 MB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:00 1.02 MB/s
wincertstore-0 100% |###############################| Time: 0:00:00 4.84 MB/s
setuptools-36. 100% |###############################| Time: 0:00:00 1.64 MB/s
pip-9.0.1-py36 100% |###############################| Time: 0:00:01 1.68 MB/s
Extracting packages ...
[ COMPLETE ]|##################################################| 100%
Linking packages ...
An unexpected error has occurred. | 0%
Please consider posting the following information to the
conda GitHub issue tracker at:
https://github.com/conda/conda/issues
Current conda install:
platform : win-64
conda version : 4.2.7
conda is private : False
conda-env version : 4.2.7
conda-build version : not installed
python version : 3.9.12.final.0
requests version : 2.28.1
root environment : C:\Users\user\AppData\Local\Programs\Python\Python39 (writable)
default environment : C:\Users\user\AppData\Local\Programs\Python\Python39
envs directories : C:\Users\user\AppData\Local\Programs\Python\Python39\envs
package cache : C:\Users\user\AppData\Local\Programs\Python\Python39\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
https://repo.continuum.io/pkgs/msys2/win-64/
https://repo.continuum.io/pkgs/msys2/noarch/
config file : None
offline mode : False
$ C:\Users\user\miniconda3\Scripts\conda-script.py create -n nam python
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\install.py", line 201, in yield_lines
with open(path) as fh:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python39\\pkgs\\vs2015_runtime-14.0.25420-0\\info\\has_prefix'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\install.py", line 209, in yield_lines
raise StopIteration
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\cli\install.py", line 405, in install
execute_actions(actions, index, verbose=not context.quiet)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\plan.py", line 643, in execute_actions
inst.execute_instructions(plan, index, verbose)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\instructions.py", line 134, in execute_instructions
cmd(state, arg)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\instructions.py", line 78, in LINK_CMD
link(state['prefix'], dist, lt, index=state['index'])
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\install.py", line 943, in link
has_prefix_files = read_has_prefix(join(info_dir, 'has_prefix'))
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\install.py", line 248, in read_has_prefix
return {pr.filepath: (pr.placeholder, pr.filemode) for pr in parsed_lines}
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\install.py", line 248, in <dictcomp>
return {pr.filepath: (pr.placeholder, pr.filemode) for pr in parsed_lines}
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\install.py", line 247, in <genexpr>
parsed_lines = (parse_line(line) for line in yield_lines(path))
RuntimeError: generator raised StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\exceptions.py", line 472, in conda_exception_handler
return_value = func(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\cli\main.py", line 144, in _main
exit_code = args.func(args, p)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\cli\main_create.py", line 68, in execute
install(args, parser, 'create')
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\conda\cli\install.py", line 420, in install
raise CondaRuntimeError('RuntimeError: %s' % e)
conda.exceptions.CondaRuntimeError: Runtime error: RuntimeError: generator raised StopIteration
my version is conda 4.2 and
I discovered that it's no longer supported, so I used conda update conda and got
PackageNotFoundError: Package not found: 'conda' Package 'conda' is not installed in C:\Users\user\AppData\Local\Programs\Python\Python39
, tried to reinstall anaconda and still got the same error.
"C:\Users\user\AppData\Local\Programs\Python\Python39"
has nothing to do with Anaconda. This the path where standard Python from python.org is installed. Why didn't you mention the 2 Python installations?
Anyhow, before you can use Anaconda you have activate it, preferably using the Anaconda prompt. Only then can you update conda.
And do yourself a favour: Either learn some conda basics from https://conda.io/projects/conda/en/latest/user-guide/getting-started.html
or remove it from your system.
I want to visualize a decision tree using graphviz.
I found some example code (https://gist.github.com/WillKoehrsen/ff77f5f308362819805a3defd9495ffd):
from sklearn.datasets import load_iris
iris = load_iris()
# Model (can also use single decision tree)
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=10)
# Train
model.fit(iris.data, iris.target)
# Extract single tree
estimator = model.estimators_[5]
from sklearn.tree import export_graphviz
# Export as dot file
export_graphviz(estimator, out_file='tree.dot',
feature_names = iris.feature_names,
class_names = iris.target_names,
rounded = True, proportion = False,
precision = 2, filled = True)
# Convert to png using system command (requires Graphviz)
from subprocess import call
call(['dot', '-Tpng', 'tree.dot', '-o', 'tree.png', '-Gdpi=600'])
# Display in jupyter notebook
from IPython.display import Image
Image(filename = 'tree.png')
What it should output:
When I do this with jupyter notebooks, however, I get a FileNotFoundError:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-3-6d9aafea91ef> in <module>()
21 # Convert to png using system command (requires Graphviz)
22 from subprocess import call
---> 23 call(['dot', '-Tpng', 'tree.dot', '-o', 'tree.png', '-Gdpi=600'])
24
25 # Display in jupyter notebook
C:\ProgramData\Anaconda3\lib\subprocess.py in call(timeout, *popenargs, **kwargs)
302 retcode = call(["ls", "-l"])
303 """
--> 304 with Popen(*popenargs, **kwargs) as p:
305 try:
306 return p.wait(timeout=timeout)
C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
754 c2pread, c2pwrite,
755 errread, errwrite,
--> 756 restore_signals, start_new_session)
757 except:
758 # Cleanup if the child failed starting.
C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1153 env,
1154 os.fspath(cwd) if cwd is not None else None,
-> 1155 startupinfo)
1156 finally:
1157 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
(The last one says that my system was not able to find the stated file)
With Anaconda Prompt in admin mode I ran conda install -c anaconda graphviz with no errors:
Collecting package metadata: done
Solving environment: \
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
- defaults/win-64::anaconda==5.3.1=py37_0
- defaults/win-64::astropy==3.0.4=py37hfa6e2cd_0
- defaults/win-64::bkcharts==0.2=py37_0
- defaults/win-64::blaze==0.11.3=py37_0
- defaults/win-64::bokeh==0.13.0=py37_0
- defaults/win-64::bottleneck==1.2.1=py37h452e1ab_1
- defaults/win-64::dask==0.19.1=py37_0
- defaults/win-64::datashape==0.5.4=py37_1
- defaults/win-64::h5py==2.8.0=py37h3bdd7fb_2
- defaults/win-64::imageio==2.4.1=py37_0
- defaults/win-64::matplotlib==2.2.3=py37hd159220_0
- defaults/win-64::mkl-service==1.1.2=py37hb217b18_5
- defaults/win-64::mkl_fft==1.0.4=py37h1e22a9b_1
- defaults/win-64::mkl_random==1.0.1=py37h77b88f5_1
- defaults/win-64::numba==0.39.0=py37h830ac7b_0
- defaults/win-64::numexpr==2.6.8=py37h9ef55f4_0
- defaults/win-64::numpy==1.15.1=py37ha559c80_0
- defaults/win-64::numpy-base==1.15.1=py37h8128ebf_0
- defaults/win-64::odo==0.5.1=py37_0
- defaults/win-64::pandas==0.23.4=py37h830ac7b_0
- defaults/win-64::patsy==0.5.0=py37_0
- defaults/win-64::pytables==3.4.4=py37he6f6034_0
- defaults/win-64::pytest-arraydiff==0.2=py37h39e3cac_0
- defaults/win-64::pytest-astropy==0.4.0=py37_0
- defaults/win-64::pytest-doctestplus==0.1.3=py37_0
- defaults/win-64::pywavelets==1.0.0=py37h452e1ab_0
- defaults/win-64::scikit-image==0.14.0=py37h6538335_1
- defaults/win-64::scikit-learn==0.19.2=py37heebcf9a_0
- defaults/win-64::scipy==1.1.0=py37h4f6bf74_1
- defaults/win-64::seaborn==0.9.0=py37_0
- defaults/win-64::statsmodels==0.9.0=py37h452e1ab_0
done
## Package Plan ##
environment location: C:\ProgramData\Anaconda3
added / updated specs:
- graphviz
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2019.1.23 | 0 158 KB anaconda
certifi-2019.3.9 | py37_0 155 KB anaconda
conda-4.6.12 | py37_1 2.1 MB anaconda
graphviz-2.38.0 | 4 37.7 MB anaconda
openssl-1.1.1 | he774522_0 5.7 MB anaconda
vc-14.1 | h21ff451_3 5 KB anaconda
vs2015_runtime-15.5.2 | 3 2.2 MB anaconda
------------------------------------------------------------
Total: 48.1 MB
The following packages will be UPDATED:
openssl conda-forge::openssl-1.1.1b-hfa6e2cd_2 --> anaconda::openssl-1.1.1-he774522_0
vs2015_runtime pkgs/main::vs2015_runtime-14.15.26706~ --> anaconda::vs2015_runtime-15.5.2-3
The following packages will be SUPERSEDED by a higher-priority channel:
ca-certificates conda-forge::ca-certificates-2019.3.9~ --> anaconda::ca-certificates-2019.1.23-0
certifi conda-forge --> anaconda
conda conda-forge::conda-4.6.12-py37_2 --> anaconda::conda-4.6.12-py37_1
graphviz conda-forge::graphviz-2.38.0-h6538335~ --> anaconda::graphviz-2.38.0-4
vc pkgs/main::vc-14.1-h0510ff6_4 --> anaconda::vc-14.1-h21ff451_3
Proceed ([y]/n)? y
Downloading and Extracting Packages
certifi-2019.3.9 | 155 KB | ############################################################################ | 100%
conda-4.6.12 | 2.1 MB | ############################################################################ | 100%
graphviz-2.38.0 | 37.7 MB | ############################################################################ | 100%
openssl-1.1.1 | 5.7 MB | ############################################################################ | 100%
vc-14.1 | 5 KB | ############################################################################ | 100%
ca-certificates-2019 | 158 KB | ############################################################################ | 100%
vs2015_runtime-15.5. | 2.2 MB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Suprisingly, it worked just fine when I ran the code on kaggle.com.
Any ideas on what could be the problem and how to solve it?
Just solved this.
The trick was to add the graphviz path to the windows environmental variables, here is a good description: https://bobswift.atlassian.net/wiki/spaces/GVIZ/pages/20971549/How+to+install+Graphviz+software
I restarted my computer after this and voila.
(OSX = Mountain lion) My app in /dist throws the error:
Last login: Wed Aug 28 11:21:29 on ttys001
-MacBook-Pro:~ $ /Users/Desktop/dist/abc.app/Contents/MacOS/abc ; exit;
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/py2app/apptemplate/lib/site.py", line 20, in <module>
import os
File "os.pyc", line 398, in <module>
File "UserDict.pyc", line 83, in <module>
File "_abcoll.pyc", line 11, in <module>
File "/Users/Virendra/Desktop/dist/abc.app/Contents/Resources/abc.py", line 6, in <module>
import psutil
File "build/bdist.macosx-10.8-x86_64/egg/psutil/__init__.py", line 54, in <module>
File "build/bdist.macosx-10.8-x86_64/egg/psutil/_common.py", line 16, in <module>
File "build/bdist.macosx-10.8-x86_64/egg/psutil/_compat.py", line 65, in <module>
File "collections.pyc", line 6, in <module>
AttributeError: 'module' object has no attribute '__all__'
logout
My setup.py (same error even without the - 'import os') looks like:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['abc.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True, 'includes': ['psutil', 'time', 'socket', 'os']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
And the scrip abc.py in question:
from psutil import cpu_times_percent
import socket
import time
serverHost = "localhost"
thisClient = socket.gethostname()
cpuStats = psutil.cpu_times_percent()
print cpuStats
currentTime = int(time.time())
s = socket.socket()
s.connect((serverHost,8080))
command = 'put cpu.usr ' + str(currentTime) + " " + str(cpuStats[0]) + " host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.nice ' + str(currentTime) + " " + str(cpuStats[1]) +" host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.sys ' + str(currentTime) + " " + str(cpuStats[2]) + " host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.idle ' + str(currentTime) + " " + str(cpuStats[3]) + " host="+ thisClient+ "\n"
s.sendall(command)
s.close()
Initially it was 'import psutil' which I changed to the 'from psutil...' as above. Included the 'import os...' here. But all combinations throw the same error. Elsewhere, I have seen 'import psutil' as a standard import and this is no different. What else could the error AttributeError: 'module' object has no attribute '__all__' mean? Thx.
Your script file, abc.py, conflicts with the Python standard library Abstract Base Class module, abc. The simplest solution should be to just change the name of your file to something else.
import pexpect, os, sys
cmd = "sudo su -"
p = pexpect.spawn(cmd, timeout=60)
pass_expect = ".*assword.*" (as I get a prompt saying "[sudo] password for user" )
p.expect(pass_expect)
print "I want the password"
p.sendline("mypassword")
p.logfile = sys.stdout
p.sendline("logout")
p.close()
I am getting the following error while executing the above script
Error
Traceback (most recent call last):
File "test.py", line 11, in
p.expect(pass_expect)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
version: 2.3 ($Revision: 399 $)
command: /usr/bin/sudo
args: ['/usr/bin/sudo', 'su', '-']
searcher: searcher_re:
0: re.compile(".*assword.*")
buffer (last 100 chars): root#:~#
before (last 100 chars): root#:~#
after:
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 16933
child_fd: 3
closed: False
timeout: 60
delimiter:
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
Can someone please help me out as I am been stuck in this problem from few days.
Any help will be appreciated.
Thanks !!
If you login as a superuser means put root#localhost
child = pexpect.spawn("ssh root#localhost")
child.logfile = open("/tmp/mylog", "w")
child.expect(".*assword:")
child.send("guest\r")
child.expect(".*\$ ")
child.sendline("python -V\r")
print child.before
How to login the super user(root) in remote host system using pexpect?