|
1 | | -def imports(): |
2 | | - """Try importing most required modules for this library""" |
3 | | - try: |
4 | | - import requests |
5 | | - except ImportError as packet: |
6 | | - install([packet.name]) |
| 1 | +input("This program should help you install lxml and requests modules, using many different methods. Press Enter to continue.") |
| 2 | +try: |
| 3 | + from pip._internal import main |
| 4 | + main(['install', "lxml"]) |
| 5 | + main(['install', "requests"]) |
| 6 | + import lxml |
| 7 | + import requests |
| 8 | +except: |
7 | 9 | try: |
| 10 | + import pip |
| 11 | + pip.main(['install', "lxml"]) |
| 12 | + pip.main(['install', "requests"]) |
8 | 13 | import lxml |
9 | | - except ImportError as packet: |
10 | | - install([packet.name]) |
| 14 | + import requests |
11 | 15 |
|
12 | | -def install(packets): |
13 | | - import subprocess |
14 | | - for packet in packets: |
| 16 | + except: |
15 | 17 | try: |
16 | | - subprocess.call(['pip', 'install', packet.strip()]) |
17 | | - except Exception as e: |
18 | | - print(e) |
19 | | - input("Press any key to continue") |
20 | | - |
21 | | - |
22 | | -if __name__ == "__main__": |
23 | | - imports() |
24 | | - packets = input("Pls write the packets names you want to install (separated by a comma):\n").split(",") |
25 | | - install(packets) |
26 | | - input("The program is over. You may close this window now.") |
| 18 | + import subprocess |
| 19 | + import sys |
| 20 | + subprocess.check_call([sys.executable, "-m", "pip", "install", "lxml"]) |
| 21 | + subprocess.check_call([sys.executable, "-m", "pip", "install", "requests"]) |
| 22 | + import lxml |
| 23 | + import requests |
| 24 | + except: |
| 25 | + try: |
| 26 | + import subprocess |
| 27 | + subprocess.call(['pip', 'install', "lxml"]) |
| 28 | + subprocess.call(['pip', 'install', "requests"]) |
| 29 | + import lxml |
| 30 | + import requests |
| 31 | + except Exception as e: |
| 32 | + print(e) |
| 33 | + print("Sorry, but i couldn't help. search in google for more options (your goal is to install requests and lxml modules") |
| 34 | + print("Here's a good place to start: https://www.google.com/search?q=Installing+python+module+within+code ") |
| 35 | + break |
| 36 | +input("Press any key to continue") |
0 commit comments