problem running "command -v dnf" in python - python-3.x

I'm trying to run this code:
import subprocess
def install_curl():
result = subprocess.check_output(['command', '-v', 'dnf']) #
if not result:
print("You should Install curl")
else:
result = subprocess.check_output(['command', '-v', 'apt'])
print(result)
install_curl()
Then I'm getting this error:
Traceback (most recent call last):
File "/home/pbravodez1/projects/Automate_task/test_gpg.py", line 98, in <module>
install_curl()
File "/home/pbravodez1/projects/Automate_task/test_gpg.py", line 91, in install_curl
result = subprocess.check_output(['command', '-v', 'dnf']) #
File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'command'
Do you have any idea on how to run this "command" in order to check which package manager is installed in the Operating System?

Related

How to specify local shell for Fabric2/Paramiko/Invoke?

When trying to create a fabric2.Connection, Paramiko tries to invoke a local /bin/bash command:
$ fab2 db-shell
Traceback (most recent call last):
File "/nix/store/m2iyj18cifr4a1rvpfgphg7kfgsf2pj2-python3.9-fabric2-2.7.1/bin/.fab2-wrapped", line 9, in <module>
sys.exit(program.run())
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/program.py", line 384, in run
self.execute()
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/program.py", line 566, in execute
executor.execute(*self.tasks)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/executor.py", line 129, in execute
result = call.task(*args, **call.kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/tasks.py", line 127, in __call__
result = self.body(*args, **kwargs)
File "/home/username/project/fabfile.py", line 645, in db_shell
bastion_connection().run(
File "/home/username/project/fabfile_utils.py", line 141, in bastion_connection
conn = Connection(
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/fabric2/connection.py", line 403, in __init__
self.ssh_config = self.config.base_ssh_config.lookup(host)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 223, in lookup
options = self._lookup(hostname=hostname)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 250, in _lookup
or self._does_match(
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 389, in _does_match
passed = invoke.run(exec_cmd, hide="stdout", warn=True).ok
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/__init__.py", line 48, in run
return Context().run(command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/context.py", line 95, in run
return self._run(runner, command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/context.py", line 102, in _run
return runner.run(command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 380, in run
return self._run_body(command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 431, in _run_body
self.start(command, self.opts["shell"], self.env)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 1291, in start
self.process = Popen(
File "/nix/store/0zzvjh5gnz0ny7ckilzyn9hmg5lypszf-python3-3.9.13/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/nix/store/0zzvjh5gnz0ny7ckilzyn9hmg5lypszf-python3-3.9.13/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/bin/bash'
I've not been able to find anything in the docs about this yet.
I'm running fabric2==2.7.1, invoke==1.6.0, and paramiko==2.8.0 on NixOS stable 22.11.
Invoke currently defaults to /bin/bash, which is a known issue, since operating systems like Alpine and NixOS don't have that path. Fortunately we can specify a command in $PATH rather than manually looking it up, so adding the following to the Connection call does the trick: config=invoke.Config(overrides={"shell": "bash"}).

Error installing pixiedust in using Jupyter

I hope you're doing well.
I am trying to follow the Pixiedust installation as laid out on the official github (https://pixiedust.github.io/pixiedust/install.html), and install it in windows 10 (64 bit).
when I try to execute instruction “jupyter pixiedust install” I get this error as “OSError: [WinError 193] %1 is not a valid Win32 application”. Let me say this too I was installed Spark (2.4.7) before. I will be very grateful if you help me.
(base) C:\>jupyter pixiedust install
←[32;1mStep 1: PIXIEDUST_HOME: C:\Pixiedust←[0m
Keep y/n [y]? y
←[32;1mStep 2: SPARK_HOME: C:\Spark\spark-2.4.7-bin-hadoop2.7←[0m
Keep y/n [y]? y
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\jupyter-pixiedust-script.py", line 33, in <module>
sys.exit(load_entry_point('pixiedust', 'console_scripts', 'jupyter-pixiedust')())
File "c:\pixiedust\install\pixiedustapp.py", line 41, in main
PixiedustJupyterApp.launch_instance()
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 844, in launch_instance
app.initialize(argv)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in inner
return method(app, *args, **kwargs)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 333, in initialize
self.parse_command_line(argv)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in inner
return method(app, *args, **kwargs)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 684, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in inner
return method(app, *args, **kwargs)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 603, in initialize_subcommand
self.subapp.initialize(argv)
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 87, in inner
return method(app, *args, **kwargs)
File "C:\Anaconda3\lib\site-packages\jupyter_core\application.py", line 241, in initialize
self.parse_command_line(argv)
File "c:\pixiedust\install\createKernel.py", line 154, in parse_command_line
spark_version = self.get_spark_version()
File "c:\pixiedust\install\createKernel.py", line 379, in get_spark_version
pyspark_out = subprocess.check_output([pyspark, "--version"], stderr=subprocess.STDOUT).decode("utf-8")
File "C:\Anaconda3\lib\subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Anaconda3\lib\subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Anaconda3\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Anaconda3\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
(base) C:\>

Running Python 3 in Jupyter Notebook but getting kernel error

Here is the error log that I get when I click on Kernel Error:
Traceback (most recent call last):
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/web.py", line 1699, in
_execute result = await result
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-
packages/notebook/services/sessions/handlers.py", line 72, in post type=mtype))
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
value = future.result()
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site
packages/notebook/services/sessions/sessionmanager.py", line 88, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
value = future.result()
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-
packages/notebook/services/sessions/sessionmanager.py", line 101, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
value = future.result()
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-
packages/notebook/services/kernels/kernelmanager.py", line 168, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-
packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line
259, in start_kernel**kw)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 204,
in _launch_kernel return launch_kernel(kernel_cmd, **kw)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/site-packages/jupyter_client/launcher.py", line
138, in launch_kernel proc = Popen(cmd, **kwargs)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/Users/Brahmbha/opt/anaconda3/lib/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory:
'/Users/Brahmbha/anaconda2/envs/ipykernel_py3/bin/python':
'/Users/Brahmbha/anaconda2/envs/ipykernel_py3/bin/python'
It looks like your jupyter notebook could be trying to use a python enviroment that has been moved or deleted.
Try this in cmd or anaconda:
python -m ipykernel install --user
See this thread for more:
https://github.com/jupyter/notebook/issues/4079

subprocess fails to call a function

I am trying to call a function using subprocess.Popen as:
proc = subprocess.Popen(["/usr/local/bin/qstat", "-u", "rudrab"],stdout=subprocess.PIPE)
numjobs = proc.stdout.read()
which is giving error:
Traceback (most recent call last):
File "genpos.py", line 159, in <module>
proc = subprocess.Popen(["/usr/local/bin/qstat", "-u", "rudrab"],stdout=subprocess.PIPE)
File "/opt/python-3.5/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/opt/python-3.5/lib/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/qstat'
but qstat is in my path:
which qstat
/usr/local/bin/qstat
what I am doing wrong here?

kernel died when launching jupyter notebook

I have installed Python 3.6 with Anaconda 3.
The installation was successful however, when I launch a notebook, there is
kernel error immediatly with the following error message :
Traceback (most recent call last):
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\notebook\base\handlers.py", line 516, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1055, in run
value = future.result()
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\concurrent.py",
line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\notebook\services\sessions\handlers.py", line 75, in post
type=mtype))
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1055, in run
value = future.result()
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\concurrent.py",
line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\notebook\services\sessions\sessionmanager.py", line 79, in
create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name,
type, kernel_name)
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1055,
in run
value = future.result()
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\concurrent.py",
line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\notebook\services\sessions\sessionmanager.py", line 92, in
start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line
1055, in run
value = future.result()
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\concurrent.py",
line 238, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "C:\Users\Lionel\Anaconda3\lib\site-packages\tornado\gen.py", line 307,
in wrapper
yielded = next(result)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\notebook\services\kernels\kernelmanager.py", line 94, in
start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\jupyter_client\manager.py", line 257, in start_kernel
**kw)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\jupyter_client\manager.py", line 203, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "C:\Users\Lionel\Anaconda3\lib\site-
packages\jupyter_client\launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "C:\Users\Lionel\Anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\Lionel\Anaconda3\lib\subprocess.py", line 997, in
_execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
Note that before installing Anaconda 3, I uninstalled Anaconda 2 (with Python 2.7).
How can I fix this?
Finally I found a solution in the web :
I had to execute the following command :
python -m ipykernel install --user
Regards,
Lionel

Resources