我正在尝试为centos中的所有系统用户安装python模块。但模块在成功安装后未导入
#!/usr/bin/env python3
import os
import sys
import subprocess
import time
def testImport():
subprocess.call(" ".join(['sudo', 'pip-3', 'install', '--user','yaspin', 'wheel', 'netifaces']), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# time.sleep(5)
try:
import yaspin
import netifaces
print("done")
except Exception as e:
print("error")
subprocess.call(" ".join(['sudo', 'pip-3', 'uninstall', '-y', 'yaspin', 'wheel', 'netifaces']), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def main(asd):
testImport()
if __name__ == "__main__":
sys.exit(main(sys.argv))这是我的脚本。
下面是堆栈跟踪
Collecting yaspin
Using cached https://files.pythonhosted.org/packages/83/15/947df8e1cb05ec01346e7b50d167898e336417abfcb72548dbdada66f361/yaspin-0.17.0-py2.py3-none-any.whl
Collecting wheel
Using cached https://files.pythonhosted.org/packages/8c/23/848298cccf8e40f5bbb59009b32848a4c38f4e7f3364297ab3c3e2e2cd14/wheel-0.34.2-py2.py3-none-any.whl
Collecting netifaces
Using cached https://files.pythonhosted.org/packages/0c/9b/c4c7eb09189548d45939a3d3a6b3d53979c67d124459b27a094c365c347f/netifaces-0.10.9-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: yaspin, wheel, netifaces
Successfully installed netifaces-0.10.9 wheel-0.34.2 yaspin-0.17.0
Traceback (most recent call last):
File "./test.py", line 25, in <module>
sys.exit(main(sys.argv))
File "./test.py", line 21, in main
testImport()
File "./test.py", line 12, in testImport
import yaspin
ModuleNotFoundError: No module named 'yaspin'发布于 2020-07-02 21:32:03
好的,这里我所理解的是,一旦python脚本启动,它就会预加载包。因此,如果您使用脚本在内部安装它,那么它可能在同一个脚本中不可用。
https://stackoverflow.com/questions/62696849
复制相似问题