Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 5640575

Browse files
authored
Update install_packets.py
1 parent d81a1de commit 5640575

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

Help_functions/install_packets.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
11
input("This program should help you install lxml and requests modules, using many different methods. Press Enter to continue.")
2-
try:
2+
3+
4+
def method1(package):
35
from pip._internal import main
4-
main(['install', "lxml"])
5-
main(['install', "requests"])
6+
main(['install', package])
7+
import requests
68
import lxml
9+
10+
def method2(package):
11+
import pip
12+
pip.main(['install', package])
713
import requests
8-
except:
9-
try:
10-
import pip
11-
pip.main(['install', "lxml"])
12-
pip.main(['install', "requests"])
13-
import lxml
14-
import requests
14+
import lxml
15+
16+
def method3(package):
17+
import subprocess
18+
import sys
19+
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
20+
import requests
21+
import lxml
22+
23+
def method4(package):
24+
import subprocess
25+
subprocess.call(['pip', 'install', package])
26+
import requests
27+
import lxml
28+
1529

30+
for package in ["lxml", "requests"]:
31+
try:
32+
method1(package)
1633
except:
1734
try:
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
35+
method2(package)
2436
except:
2537
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
38+
method3(package)
39+
except:
40+
try:
41+
method4(package)
42+
except Exception as e:
43+
print(e)
44+
print("Sorry, but i couldn't help. search in google for more options (your goal is to install requests and lxml modules")
45+
print("Here's a good place to start: https://www.google.com/search?q=Installing+python+module+within+code ")
3646
input("Press any key to continue")
47+
48+

0 commit comments

Comments
 (0)