首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法导入模块以在系统范围内安装python 3模块

无法导入模块以在系统范围内安装python 3模块
EN

Stack Overflow用户
提问于 2020-07-02 20:54:56
回答 1查看 37关注 0票数 1

我正在尝试为centos中的所有系统用户安装python模块。但模块在成功安装后未导入

代码语言:javascript
复制
#!/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))

这是我的脚本。

下面是堆栈跟踪

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2020-07-02 21:32:03

好的,这里我所理解的是,一旦python脚本启动,它就会预加载包。因此,如果您使用脚本在内部安装它,那么它可能在同一个脚本中不可用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62696849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档