简体   繁体   English

Pyautogui 未导入“没有名为‘pyautogui’的模块”

[英]Pyautogui not importing "No module named 'pyautogui' "

import pyautogui

print("hello")

After running this I am presented with the following:运行后,我会看到以下内容:

C:\Users\Darkm\Anaconda3\envs\PythonChallenges\python.exe C:/Users/Darkm/PycharmProjects/PythonChallenges/Automation1.py
Traceback (most recent call last):
  File "C:/Users/Darkm/PycharmProjects/PythonChallenges/Automation1.py", line 1, in <module>
    import pyautogui
ModuleNotFoundError: No module named 'pyautogui'

Process finished with exit code 1

Could somebody help me understand why I cannot import pyautogui?有人能帮我理解为什么我不能导入 pyautogui 吗?

Some background information:一些背景信息:

1.) I only have one version of python (3.7.4) 1.) 我只有一个版本的 python (3.7.4)

2.) I have already installed the module through "pip install pyautogui" in cmd prompt. 2.) 我已经在 cmd 提示符下通过“pip install pyautogui”安装了模块。

3.) Pyautogui is installed under C:\Users\Darkm\Anaconda3\Lib\site-packages 3.) Pyautogui安装在C:\Users\Darkm\Anaconda3\Lib\site-packages下

4.) Pyautogui does not show up when I go into file > settings > project interpreter and try to add it manually (it just doesn't show up). 4.) 当我进入文件 > 设置 > 项目解释器并尝试手动添加它时,Pyautogui 没有出现(它只是没有出现)。

5.) Have restarted computer multiple times 5.) 多次重启电脑

At this point I cannot figure out why I'm unable to import pyautogui, any help would be greatly appreciated!此时我不明白为什么我无法导入 pyautogui,任何帮助将不胜感激!

Why are you getting this error?你为什么会收到这个错误?

Because you are using PyCharm.因为你使用的是PyCharm。

In PyCharm you don't need to install python packages from command prompt, in PyCharm you need to install python packages from PyCharm Project Interpreter.在 PyCharm 中,您不需要从命令提示符安装 python 包,在 PyCharm 中,您需要从 PyCharm Project Interpreter 安装 python 包。

Here are some tips that can help you!这里有一些技巧可以帮助你!

Step 1: Go to PyCharm settings and go to this directory: Preferences and select Interpreter Settings第一步:进入PyCharm设置,进入这个目录: Preferences,选择Interpreter Settings

Screenshot:截屏:

在此处输入图像描述

Step 2: Click on this plus icon.第 2 步:单击此加号图标。

Screenshot:截屏:

在此处输入图像描述

Step 3: Type your package name and select package.第 3 步:输入您的包裹名称并选择包裹。

Screenshot:截屏:

在此处输入图像描述

Step4: Then click on install button.第四步:然后点击安装按钮。

在此处输入图像描述

Step 5: Click on okay第五步:点击确定

Then wait for two to three minutes and try again.然后等待两到三分钟,然后重试。

Hopefully it'll work.希望它能奏效。

You and also do this trick on imports你也对进口做这个把戏

import subprocess

try:
    import pyautogui
except ImportError:
    subprocess.call("pip install pyautogui")`

It's probably because of pycharm.应该是pycharm的原因吧。

If it's not pycharm and you still have problems you can try:如果它不是 pycharm 并且你仍然有问题,你可以尝试:

Cmd:命令:

python -m pip install < module >

To append to PYTHONPATH:追加到 PYTHONPATH:

IDE:集成开发环境:

import sys
sys.path.append('< path >')
import pyautogui

print("hello")

After running this I am presented with the following:运行此程序后,我会看到以下内容:

C:\Users\Darkm\Anaconda3\envs\PythonChallenges\python.exe C:/Users/Darkm/PycharmProjects/PythonChallenges/Automation1.py
Traceback (most recent call last):
  File "C:/Users/Darkm/PycharmProjects/PythonChallenges/Automation1.py", line 1, in <module>
    import pyautogui
ModuleNotFoundError: No module named 'pyautogui'

Process finished with exit code 1

Could somebody help me understand why I cannot import pyautogui?有人可以帮我理解为什么我不能导入 pyautogui 吗?

Some background information:一些背景资料:

1.) I only have one version of python (3.7.4) 1.) 我只有一个版本的 python (3.7.4)

2.) I have already installed the module through "pip install pyautogui" in cmd prompt. 2.) 我已经在 cmd 提示符下通过“pip install pyautogui”安装了模块。

3.) Pyautogui is installed under C:\Users\Darkm\Anaconda3\Lib\site-packages 3.) Pyautogui 安装在 C:\Users\Darkm\Anaconda3\Lib\site-packages 下

4.) Pyautogui does not show up when I go into file > settings > project interpreter and try to add it manually (it just doesn't show up). 4.) 当我 go 进入文件 > 设置 > 项目解释器并尝试手动添加它时,Pyautogui 没有出现(它只是没有出现)。

5.) Have restarted computer multiple times 5.) 多次重启电脑

At this point I cannot figure out why I'm unable to import pyautogui, any help would be greatly appreciated!此时我无法弄清楚为什么我无法导入 pyautogui,任何帮助将不胜感激!

If you face module not found on Jupyter environment you had to install it on Jupyter environment instead of installing it on command prompt如果您遇到在 Jupyter 环境中找不到的模块,您必须在 Jupyter 环境中安装它,而不是在命令提示符下安装它

by this command (for windows)通过此命令(适用于 Windows)

!pip install pyautogui

After that you can easily import and use it.之后,您可以轻松导入并使用它。 Whenever you want to tell Jupyter that this is system command you should put !每当你想告诉 Jupyter 这是你应该输入的系统命令时! before your command.在你的命令之前。

Make sure you have the latest version of python installed on your computer确保您的计算机上安装了最新版本的 python

On Windows :在 Windows 上

Open up Windows PowerShell .打开Windows PowerShell Type py -m pip install pyautogui and wait for 2 minutes . py -m pip install pyautogui并等待2 分钟 Then, restart your IDE .然后,重新启动您的IDE Try running your code, it should work now.尝试运行您的代码,它现在应该可以工作了。

On a Mac :在 Mac 上

Open up iTerm .打开iTerm Type pip3 install pyautogui or py -m pip3 install pyautogui , and wait for 2 minutes .键入pip3 install pyautoguipy -m pip3 install pyautogui ,然后等待2 分钟 Then, restart your IDE .然后,重新启动您的IDE Then just simply try to run your code, it should be working.然后只需简单地尝试运行您的代码,它应该可以正常工作。

Hope this helped!希望这有帮助!

Try this...试试这个...

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy

Tutorial from Pythonic Perambulations 来自 Pythonic Perambulations 的教程

Go to terminal.去终端。 type "pip install pyautogui"输入“pip install pyautogui”

pip install pyautogui

Your problem should be solved now.你的问题现在应该已经解决了。 If it isn't try this.如果不是试试这个。

!pip install pyautogui

You are using Pycharm IDE.您正在使用 Pycharm IDE。 To install packages in Pycharm, you can use the project interpreter in settings or type the following in the terminal:要在 Pycharm 中安装包,您可以使用设置中的项目解释器或在终端中键入以下内容:

pip install pyautogui

make sure that library is installed in same version of python确保库安装在相同版本的 python 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM