【问题标题】:How can I import modules in python?如何在 python 中导入模块?
【发布时间】:2016-07-08 07:31:33
【问题描述】:

我从here 下载了 pyautogui,但它不允许我导入它或使用它允许新 python 文件的任何功能,即使我已经在该文件中运行了安装文件并且已经写了

pip install pyautogui

import pyautogui

import module pyautogui

在 python IDLE 模块中。

我在 python 3.4.2 中执行此操作,只是返回错误提示找不到它。

编辑:

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> pip install pyautogui
SyntaxError: invalid syntax
>>> 

“安装”一词以红色突出显示

【问题讨论】:

  • 你运行的是什么操作系统?你链接的页面说 OS X 和 Linux 系统有额外的依赖项,你需要安装。
  • Windows 10 操作系统。
  • 好的,那么猜测是路径配置问题。你的pyautogui的路径和安装位置是什么?只是为了确定,你得到的确切错误是什么? (例如,import module pyautogui 应该只给你一个 SyntaxError。)
  • 这是一个语法错误,pyautogui 在下载文件夹 (ThisPC\Downloads) 中并被提取(解压缩)到桌面
  • 我的意思是确切的错误信息。您必须在终端中运行pip install pyautogui,而不是在 IDLE 中。是你做的吗?如果没有,请尝试。如果是,import pyautogui 的输出和import sys, print(sys.path) 的输出是什么?这可能会很长,所以请edit 并添加到您的原始帖子中,而不是放入 cmets。

标签: python-3.x module pyautogui


【解决方案1】:

尝试使用 Python 安装 pyautogui 的代码:-

import os
os.system("pip install pyautogui")

然后尝试导入库

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-08
    • 2015-06-18
    • 2014-01-13
    • 2023-03-19
    • 1970-01-01
    • 2022-12-09
    • 2021-12-28
    相关资源
    最近更新 更多