How can I make python detect missing packages or apps [closed]
I'm making a script for Ethical Hacking purposes and I want to have a first function that detects and shows the user what packages they need to install before they can continue. For example, I would like it to detect if the user has nmap
or aircrack-ng
in their Linux systems!
linux python
closed as off-topic by Jeff Schaller, Olorin, Mr Shunz, jimmij, Archemar Feb 8 at 10:29
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I'm making a script for Ethical Hacking purposes and I want to have a first function that detects and shows the user what packages they need to install before they can continue. For example, I would like it to detect if the user has nmap
or aircrack-ng
in their Linux systems!
linux python
closed as off-topic by Jeff Schaller, Olorin, Mr Shunz, jimmij, Archemar Feb 8 at 10:29
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
@JeffSchaller Iḿ using linux mint!
– user270399
Feb 7 at 19:58
1
If Iimport foo
and modulefoo
is not found by python, I get ab exception that says:ModuleNotFoundError: No module named 'foo'
- is that not enough? If not, what more do you want?
– NickD
Feb 7 at 20:04
pip list
orpip freeze
will show installed Python modules. It should be enough to just compare the output what modules the user needs to run the script. As previously mentioned, if the module isn't there then they will see the error that it's not found.
– Nasir Riley
Feb 8 at 0:08
@NickD I want it detect packeges like aircrack-ng that arent python related !
– user270399
Feb 14 at 20:12
add a comment |
I'm making a script for Ethical Hacking purposes and I want to have a first function that detects and shows the user what packages they need to install before they can continue. For example, I would like it to detect if the user has nmap
or aircrack-ng
in their Linux systems!
linux python
I'm making a script for Ethical Hacking purposes and I want to have a first function that detects and shows the user what packages they need to install before they can continue. For example, I would like it to detect if the user has nmap
or aircrack-ng
in their Linux systems!
linux python
linux python
edited Feb 8 at 3:27
wjandrea
498413
498413
asked Feb 7 at 14:13
user270399
closed as off-topic by Jeff Schaller, Olorin, Mr Shunz, jimmij, Archemar Feb 8 at 10:29
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Jeff Schaller, Olorin, Mr Shunz, jimmij, Archemar Feb 8 at 10:29
- This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
@JeffSchaller Iḿ using linux mint!
– user270399
Feb 7 at 19:58
1
If Iimport foo
and modulefoo
is not found by python, I get ab exception that says:ModuleNotFoundError: No module named 'foo'
- is that not enough? If not, what more do you want?
– NickD
Feb 7 at 20:04
pip list
orpip freeze
will show installed Python modules. It should be enough to just compare the output what modules the user needs to run the script. As previously mentioned, if the module isn't there then they will see the error that it's not found.
– Nasir Riley
Feb 8 at 0:08
@NickD I want it detect packeges like aircrack-ng that arent python related !
– user270399
Feb 14 at 20:12
add a comment |
@JeffSchaller Iḿ using linux mint!
– user270399
Feb 7 at 19:58
1
If Iimport foo
and modulefoo
is not found by python, I get ab exception that says:ModuleNotFoundError: No module named 'foo'
- is that not enough? If not, what more do you want?
– NickD
Feb 7 at 20:04
pip list
orpip freeze
will show installed Python modules. It should be enough to just compare the output what modules the user needs to run the script. As previously mentioned, if the module isn't there then they will see the error that it's not found.
– Nasir Riley
Feb 8 at 0:08
@NickD I want it detect packeges like aircrack-ng that arent python related !
– user270399
Feb 14 at 20:12
@JeffSchaller Iḿ using linux mint!
– user270399
Feb 7 at 19:58
@JeffSchaller Iḿ using linux mint!
– user270399
Feb 7 at 19:58
1
1
If I
import foo
and module foo
is not found by python, I get ab exception that says: ModuleNotFoundError: No module named 'foo'
- is that not enough? If not, what more do you want?– NickD
Feb 7 at 20:04
If I
import foo
and module foo
is not found by python, I get ab exception that says: ModuleNotFoundError: No module named 'foo'
- is that not enough? If not, what more do you want?– NickD
Feb 7 at 20:04
pip list
or pip freeze
will show installed Python modules. It should be enough to just compare the output what modules the user needs to run the script. As previously mentioned, if the module isn't there then they will see the error that it's not found.– Nasir Riley
Feb 8 at 0:08
pip list
or pip freeze
will show installed Python modules. It should be enough to just compare the output what modules the user needs to run the script. As previously mentioned, if the module isn't there then they will see the error that it's not found.– Nasir Riley
Feb 8 at 0:08
@NickD I want it detect packeges like aircrack-ng that arent python related !
– user270399
Feb 14 at 20:12
@NickD I want it detect packeges like aircrack-ng that arent python related !
– user270399
Feb 14 at 20:12
add a comment |
2 Answers
2
active
oldest
votes
For Python modules I use code like this:
# Make sure we have all our necessary modules
allOK=True
for m in ['requests','json','yaml','argparse','re','traceback']:
try:
globals()[m]=importlib.import_module(m)
except Exception as e:
print 'Python module "%s" is required, please use "yum install python-%s" to install it.' % (m,m)
allOK=False
if not allOK:
print 'One or more modules missing, exiting.'
exit(1)
Might be better to just catchImportError
instead of all exceptions
– wjandrea
Feb 8 at 1:33
add a comment |
For packages, just trying to install them is the easiest, but something like parsing the output of rpm -qa
(or equivalent for other packaging schemes) would work. If it's a Python module, you could have a try
-except
statement where the except
clause can install the package containing the module and try the import again.
Was that the question, or are we all confused?
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
For Python modules I use code like this:
# Make sure we have all our necessary modules
allOK=True
for m in ['requests','json','yaml','argparse','re','traceback']:
try:
globals()[m]=importlib.import_module(m)
except Exception as e:
print 'Python module "%s" is required, please use "yum install python-%s" to install it.' % (m,m)
allOK=False
if not allOK:
print 'One or more modules missing, exiting.'
exit(1)
Might be better to just catchImportError
instead of all exceptions
– wjandrea
Feb 8 at 1:33
add a comment |
For Python modules I use code like this:
# Make sure we have all our necessary modules
allOK=True
for m in ['requests','json','yaml','argparse','re','traceback']:
try:
globals()[m]=importlib.import_module(m)
except Exception as e:
print 'Python module "%s" is required, please use "yum install python-%s" to install it.' % (m,m)
allOK=False
if not allOK:
print 'One or more modules missing, exiting.'
exit(1)
Might be better to just catchImportError
instead of all exceptions
– wjandrea
Feb 8 at 1:33
add a comment |
For Python modules I use code like this:
# Make sure we have all our necessary modules
allOK=True
for m in ['requests','json','yaml','argparse','re','traceback']:
try:
globals()[m]=importlib.import_module(m)
except Exception as e:
print 'Python module "%s" is required, please use "yum install python-%s" to install it.' % (m,m)
allOK=False
if not allOK:
print 'One or more modules missing, exiting.'
exit(1)
For Python modules I use code like this:
# Make sure we have all our necessary modules
allOK=True
for m in ['requests','json','yaml','argparse','re','traceback']:
try:
globals()[m]=importlib.import_module(m)
except Exception as e:
print 'Python module "%s" is required, please use "yum install python-%s" to install it.' % (m,m)
allOK=False
if not allOK:
print 'One or more modules missing, exiting.'
exit(1)
answered Feb 8 at 0:28
xenoidxenoid
3,0751725
3,0751725
Might be better to just catchImportError
instead of all exceptions
– wjandrea
Feb 8 at 1:33
add a comment |
Might be better to just catchImportError
instead of all exceptions
– wjandrea
Feb 8 at 1:33
Might be better to just catch
ImportError
instead of all exceptions– wjandrea
Feb 8 at 1:33
Might be better to just catch
ImportError
instead of all exceptions– wjandrea
Feb 8 at 1:33
add a comment |
For packages, just trying to install them is the easiest, but something like parsing the output of rpm -qa
(or equivalent for other packaging schemes) would work. If it's a Python module, you could have a try
-except
statement where the except
clause can install the package containing the module and try the import again.
Was that the question, or are we all confused?
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
add a comment |
For packages, just trying to install them is the easiest, but something like parsing the output of rpm -qa
(or equivalent for other packaging schemes) would work. If it's a Python module, you could have a try
-except
statement where the except
clause can install the package containing the module and try the import again.
Was that the question, or are we all confused?
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
add a comment |
For packages, just trying to install them is the easiest, but something like parsing the output of rpm -qa
(or equivalent for other packaging schemes) would work. If it's a Python module, you could have a try
-except
statement where the except
clause can install the package containing the module and try the import again.
Was that the question, or are we all confused?
For packages, just trying to install them is the easiest, but something like parsing the output of rpm -qa
(or equivalent for other packaging schemes) would work. If it's a Python module, you could have a try
-except
statement where the except
clause can install the package containing the module and try the import again.
Was that the question, or are we all confused?
edited Feb 8 at 3:26
wjandrea
498413
498413
answered Feb 8 at 0:03
stolenmomentstolenmoment
1223
1223
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
add a comment |
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
That's ok but I steal need something that detects packages not related to python like aicrack-ng!
– user270399
Feb 14 at 20:14
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
Right, so only the first half of my answer is relevant. Parse the output of your package manager.
– stolenmoment
Feb 14 at 22:43
add a comment |
@JeffSchaller Iḿ using linux mint!
– user270399
Feb 7 at 19:58
1
If I
import foo
and modulefoo
is not found by python, I get ab exception that says:ModuleNotFoundError: No module named 'foo'
- is that not enough? If not, what more do you want?– NickD
Feb 7 at 20:04
pip list
orpip freeze
will show installed Python modules. It should be enough to just compare the output what modules the user needs to run the script. As previously mentioned, if the module isn't there then they will see the error that it's not found.– Nasir Riley
Feb 8 at 0:08
@NickD I want it detect packeges like aircrack-ng that arent python related !
– user270399
Feb 14 at 20:12