[英]Check and Install wget package at time of execution in Python
我正在尝试使用以下代码安装wget
软件包。 目的是检查软件包是否已安装。 如果未安装,请在执行代码时自动下载并安装。 以下代码适用于pandas
软件包,但不适用于wget。
import pip
# Define function to install missing modules/packages
def install(package):
pip.main(['install', package])
# Call function and install missing module/package
if __name__ == '__main__':
install('pandas')
install('wget')
# Below is the exception message received for wget.
[31mException:
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Python36\lib\site-packages\pip\commands\install.py", line 324, in run
requirement_set.prepare_files(finder)
File "C:\Python36\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Python36\lib\site-packages\pip\req\req_set.py", line 634, in _prepare_file
abstract_dist.prep_for_dist()
File "C:\Python36\lib\site-packages\pip\req\req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "C:\Python36\lib\site-packages\pip\req\req_install.py", line 439, in run_egg_info
command_desc='python setup.py egg_info')
File "C:\Python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
File "C:\Python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
return s.decode(sys.__stdout__.encoding)
AttributeError: 'NoneType' object has no attribute 'encoding'[0m
知道可能是什么问题吗? 我在Windows 7 x64位操作系统上使用Python 3.6.4。
我想从外部脚本安装它能正常工作吗? 我尝试了您的代码,它正在工作。 我试图找出发生了什么,有两种可能性:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.