Make pip_install function more flexible

sys.executable gets the python.exe used to run the script
-r allows pip to use requirements.txt
This commit is contained in:
BrianPetkovsek 2019-06-14 21:11:31 -04:00
parent fafd5fadd3
commit a1e1d98929

View File

@ -3,8 +3,9 @@
""" """
Name: Video2X Setup Script Name: Video2X Setup Script
Author: K4YT3X Author: K4YT3X
Author: BrianPetkovsek
Date Created: November 28, 2018 Date Created: November 28, 2018
Last Modified: April 28, 2019 Last Modified: June 14, 2019
Licensed under the GNU General Public License Version 3 (GNU GPL v3), Licensed under the GNU General Public License Version 3 (GNU GPL v3),
available at: https://www.gnu.org/licenses/gpl-3.0.txt available at: https://www.gnu.org/licenses/gpl-3.0.txt
@ -86,10 +87,7 @@ class Video2xSetup:
def _install_python_requirements(self): def _install_python_requirements(self):
""" Read requirements.txt and return its content """ Read requirements.txt and return its content
""" """
with open('requirements.txt', 'r') as req: pip_install('requirements.txt')
for line in req:
package = line.split('==')[0]
pip_install(package)
def _cleanup(self): def _cleanup(self):
""" Cleanup all the temp files downloaded """ Cleanup all the temp files downloaded
@ -201,13 +199,13 @@ def download(url, save_path, chunk_size=4096):
return output_file return output_file
def pip_install(package): def pip_install(file):
""" Install python package via python pip module """ Install python package via python pip module
pip.main() is not available after pip 9.0.1, thus pip.main() is not available after pip 9.0.1, thus
pip module is not used in this case. pip module is not used in this case.
""" """
return subprocess.run(['python', '-m', 'pip', 'install', '-U', package]).returncode return subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', file]).returncode
if __name__ == "__main__": if __name__ == "__main__":