1

I'm kinda pretty new to python and I wanted to import autogui into PyCharm. So I wrote: import pyautogui.

When I try to run the command, I get the message "ModuleNotFoundError: No module named 'pyautogui'".

I looked it up, and everyone said stuff like "just run pip install pyautogui in cmd" or pip3 install pyautogui or similar stuff. But that's not the problem (I think), it is already installed under C:\Python39\Lib\site-packages (I still run it everytime it doesn't work just to be save). The next thing I found was someone being told to go to the settings in PyCharm and add pyautogui as interpreter, but when I try that, it just doesn't show up.

The next thing I tried was clicking on the error in PyCharm and selecting "install package pyautogui", but all I get is this:

"Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata (repodata.json): ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  • pyautogui

Current channels:

To search for alternate channels that may provide the conda package you're looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page."

I then used anaconda.org and the anaconda prompt to install pyautogui... again.

But still, it changed nothing. I still don't find anything and it still can't install pyautogui itself with the same error message as above. All I found out is that the anaconda prompt tells me that my python version is 3.8.8 and my command prompt says it's 3.9.6. So I deinstalled 3.9.6 and installed 3.8.8 and reinstalled pyautogui, once with the pip command in cmd and once with the command in the anaconda prompt. Still, nothing works.

And yes, I already added Anaconda to path, because I saw somewhere that it's supposed to help. Well, it doesn't, and now I'm here, asking for help.

Does anybody know what I could be doing wrong?

J0nas
  • 49
  • 1
  • 6
  • you may have two Pythons installed (even with the same number) and you may use one Python to install module and PyCharm may use other Python to run code. In PyChar settings you can set path to Python used in your project. PyCharm in setting should have also function to install modules for this Python. – furas Sep 12 '21 at 13:41
  • `pyautogui` is NOT Python interpreter so don't set it as interpreter in PyCharm setting. There should be function to install modules and there you should *install* `pyautogui` – furas Sep 12 '21 at 13:43
  • in PyCharm you can run `import sys ; print( sys.executable )` to get full path to Python used for running project - on Linux I get `/usr/bin/python3.8`- and you should use this path in console to install modules - on Linux `/usr/bin/python3.8 -m pip install pyautogui` - and it should install `pyautogui` in Python whic PyCharm uses to run your code. – furas Sep 12 '21 at 13:46
  • I ran the commands and it returned 3 things: 1. the python.exe file in my project folder; 2. the main.py in my project folder and 3. the python.exe file AGAIN, two times, same path, same everything. And it's just that, python.exe. No python3.8 or anything like that. And i don't know if this is because I'm on Windows, but I also don't get anything like /usr/bin/, just the paths with the file. Also, neither the path nor -m are recognized as commands, so I don't know what I should run here – J0nas Sep 12 '21 at 14:38
  • On Windows you get `C:\path\to\python.exe` and more importat is to use this full path to install module `C:\path\to\python.exe -m pip install pyautogui` in console/terminal/cmd.exe (not in python). If you have two `python.exe` then it may means two different versions and using only `python.exe -m pip install ...` may install it with different version. Frankly I don't understand why you have `python.exe` in your folder. – furas Sep 12 '21 at 15:22
  • Yea, I don't understand it either, but I somehow got it working now. You can look at the answer I gave myself here if you want to see how I did it – J0nas Sep 12 '21 at 15:29
  • See https://stackoverflow.com/q/19885821 – bad_coder Sep 12 '21 at 16:22

3 Answers3

3

So I somehow figured it out myself with the little thoughts Ashish and furas left me.

What I did was install pyautogui with pip install pyautogui into Python. To be more specific, it downloaded it into C:\Python39\Lib\site-packages. Then, I marked all the now installed files and copied them.

After that, I went into C:\ProgramData\Anaconda3\envs\\[program name]\Lib\site-packages and pasted all the installed files into there. Now, it's working.

If someone is reading this:

Your program doesn't have to be at this specific location. you can find the location of your program by running this here in PyCharm:

import sys 
print( sys.executable )

It prints out the python.exe file of your program, for me, that was C:\ProgramData\Anaconda3\envs\\[program name]\python.exe.

So yea, it works now.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
J0nas
  • 49
  • 1
  • 6
  • now you can mark your answer as accepted and later you can upvote it. – furas Sep 12 '21 at 15:27
  • You should install using pip or whatever mechanism your virtual environment makes available. Copy-pasting files around after installing them is a mistake because some libraries might have hardcoded paths that will break if you copy paste them. – bad_coder Sep 12 '21 at 16:19
1

While getting such error even after installing the required module, check for the following:

The python environment/ installation used by your IDE should be same as the environment where the module is installed.

Else, change the environment to the Python environment paste the path to python.exe inside bin folder of your environment

And install the package again.

Specific to VS Code Click on python followed by version number or venvin the bottom ribbon of the editor and add the path to interpreter or choose an existing interpreter you want to use.

To fix failed with initial freeze error, Please try the following commands, After successful execution, you can go for the reinstallation of pyautogui.

conda config --set channel_priority false

conda install -c conda-forge pyautogui

  • I don't really know how to deinstall pyautogui, so I just ran both commands, with the second one telling me that "_All requested packages already installed_". Also, the initial freeze error still appears, so do I need to deinstall pyautogui with the anaconda prompt first? – J0nas Sep 12 '21 at 11:58
  • `pip uninstall ` will help with uninstalling the package. I would need one more piece of information, Try to ruin `pip show pyautogui` in the directory where you're running your Python code. Please confirm if you can see the installation location of the package and other details. – Ashish Papanai Sep 12 '21 at 12:02
  • So I deinstalled pyautogui, ran `conda config --set channel_priority false`, reinstalled it with `pip install autogui`, ran `cd C:\Users\Jonas\PycharmProjects\`, and finally, I ran `pip show pyautogui`. And I can confirm, it is there, all the data is being shown to me. But that didn't change anything, so now, what do I do? – J0nas Sep 12 '21 at 12:15
  • Is the `NoModuleFound` error still there? – Ashish Papanai Sep 12 '21 at 12:21
  • Yes it is, why? – J0nas Sep 12 '21 at 12:25
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 12 '21 at 13:42
0

If you have two Pythons installed (even with the same number) then you may use one Python to install module and PyCharm may use other Python to run code. But two Python doesn't share modules and every Python has to install modules in own folder.

I don't uses PyCharm but in PyCharm settings you can set path to Python used in your project (in every project you may use different Python). And PyCharm in setting should have also function to install modules for this Python. Probably it should show modules installed for selected Python and there should be icon gear to install other modules.


Other method:

In PyCharm you can run

import sys 
print( sys.executable )

to get full path to Python used by PyCharm in your project - on Linux I get /usr/bin/python3.8 but on Windows you may get C:\path\to\python.exe - and you can use this path in console/terminal/cmd.exe to install modules for this version

on Linux it looks like

/usr/bin/python3.8 -m pip install pyautogui

on Windows it will be something like

C:\path\to\python.exe -m pip install pyautogui

and it should install pyautogui in Python which PyCharm uses to run your code.

furas
  • 134,197
  • 12
  • 106
  • 148
  • I don't think that I have 2 pythons, because I deinstalled it through "add or remove programs", and I only installed one at a time from there on. Also, I ran the commands and it returned 3 things, but I already wrote the results as a comment to your other comment – J0nas Sep 12 '21 at 14:43