Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82128 > unrolled thread

[newbie] how to make program suggest to install missing modules

Started byhugocoolens <hugocoolens@gmail.com>
First post2014-12-08 09:44 -0800
Last post2014-12-08 10:23 -0800
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  [newbie] how to make program suggest to install missing modules hugocoolens <hugocoolens@gmail.com> - 2014-12-08 09:44 -0800
    Re: [newbie] how to make program suggest to install missing modules sohcahtoa82@gmail.com - 2014-12-08 10:23 -0800

#82128 — [newbie] how to make program suggest to install missing modules

Fromhugocoolens <hugocoolens@gmail.com>
Date2014-12-08 09:44 -0800
Subject[newbie] how to make program suggest to install missing modules
Message-ID<a2994123-205b-4417-ba21-6903dbfb4f4a@googlegroups.com>
I'd like to add the following to a python-program:

when a module (take rtlsdr as an example) is not installed on the system I'd like to ask the program something like:

module rtlsdr is missing, shall I install it? y or n
if n -->sorry but then I can't run this program and quit program
if y -->execute this command: 
os.system(sudo pip install pyrtlsdr)

continue program

can anyone here show me how to perform this properly?

thanks in advance
hugo

[toc] | [next] | [standalone]


#82133

Fromsohcahtoa82@gmail.com
Date2014-12-08 10:23 -0800
Message-ID<0757295c-1dac-40e8-9ebb-2128a7d41e38@googlegroups.com>
In reply to#82128
On Monday, December 8, 2014 9:44:50 AM UTC-8, hugocoolens wrote:
> I'd like to add the following to a python-program:
> 
> when a module (take rtlsdr as an example) is not installed on the system I'd like to ask the program something like:
> 
> module rtlsdr is missing, shall I install it? y or n
> if n -->sorry but then I can't run this program and quit program
> if y -->execute this command: 
> os.system(sudo pip install pyrtlsdr)
> 
> continue program
> 
> can anyone here show me how to perform this properly?
> 
> thanks in advance
> hugo

Hint:

try:
    import someModule
except ImportError:
    print "Module is missing"
    # handle it!

Just make sure to attempt to import it again after making the call to pip to install it.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web