Kevin Shum
Kevin Shum

Reputation: 43

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?

Some background information:

1.) I only have one version of python (3.7.4)

2.) I have already installed the module through "pip install pyautogui" in cmd prompt.

3.) Pyautogui is installed under 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).

5.) Have restarted computer multiple times

At this point I cannot figure out why I'm unable to import pyautogui, any help would be greatly appreciated!

Upvotes: 4

Views: 25385

Answers (10)

For the people here having this problem and actually are using VS Code, you should try installing it within a virtual environment.

I personally would recommend Python UV. Just follow the steps:

  1. Open CMD and type "pip install uv"
  2. Go to project folder and type on terminal "uv init"
  3. Now install the dependencies, always using "uv add" (ex: uv add pyautogui)
  4. Pyautogui will probably also ask you to install opencv so also type "uv add opencv-python"

Now you should be good to go.

Upvotes: 0

levan tulashvili
levan tulashvili

Reputation: 29

make sure that library is installed in same version of python

Upvotes: 0

Soham Grover
Soham Grover

Reputation: 121

You are using Pycharm IDE. To install packages in Pycharm, you can use the project interpreter in settings or type the following in the terminal:

pip install pyautogui

Upvotes: 0

user17906238
user17906238

Reputation:

Go to terminal. type "pip install pyautogui"

pip install pyautogui

Your problem should be solved now. If it isn't try this.

!pip install pyautogui

Upvotes: 0

Cleverson Felix
Cleverson Felix

Reputation: 1

Try this...

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

Tutorial from Pythonic Perambulations

Upvotes: 0

Swanith
Swanith

Reputation: 3

Make sure you have the latest version of python installed on your computer

On Windows:

Open up Windows PowerShell. Type py -m pip install pyautogui and wait for 2 minutes. Then, restart your IDE. Try running your code, it should work now.

On a Mac:

Open up iTerm. Type pip3 install pyautogui or py -m pip3 install pyautogui, and wait for 2 minutes. Then, restart your IDE. Then just simply try to run your code, it should be working.

Hope this helped!

Upvotes: 0

user11335084
user11335084

Reputation: 63

You and also do this trick on imports

import subprocess

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

Upvotes: 1

pythonic_ai
pythonic_ai

Reputation: 49

If you face module not found on Jupyter environment you had to install it on Jupyter environment instead of installing it on command prompt

by this command (for 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 ! before your command.

Upvotes: 0

tinus
tinus

Reputation: 145

It's probably because of pycharm.

If it's not pycharm and you still have problems you can try:

Cmd:

python -m pip install < module >

To append to PYTHONPATH:

IDE:

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

Upvotes: 0

Hamza Lachi
Hamza Lachi

Reputation: 1064

Why are you getting this error?

Because you are using 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.

Here are some tips that can help you!

Step 1: Go to PyCharm settings and go to this directory: Preferences and select Interpreter Settings

Screenshot:

enter image description here

Step 2: Click on this plus icon.

Screenshot:

enter image description here

Step 3: Type your package name and select package.

Screenshot:

enter image description here

Step4: Then click on install button.

enter image description here

Step 5: Click on okay

Then wait for two to three minutes and try again.

Hopefully it'll work.

Upvotes: 6

Related Questions