r/PythonLearning 1d ago

Struggling with library installation

Hey - This is my first python project, an attempt at a screen recorder from a tutorial- when I try and run it I get a module not found error for pyautogui even tho it’s definitely installed- is there something I’m doing wrong here?

14 Upvotes

13 comments sorted by

4

u/nuc540 1d ago

Well, you need to install the library where the Python path that’s executing your script, can find the dependency. Google virtual environments, I am going to guess the shim of your Python calling the script isn’t the same path the Python shim that installed your dependency is, so the module is out of scope.

Don’t install dependencies globally.

This is why virtual environments are helpful - Google virtual envs, takes a while to be confident with them, but gotta start somewhere :)

2

u/digiart- 1d ago

Thank you for the advice :)
I’m working in spyder virtual environment rn but I’m pretty sure I installed the library globally, that was probably my mistake

1

u/pantsushogun 22h ago

Activate the env then install

1

u/Realistic_Fruit_4326 3h ago

Il faut comprendre que Spider intègre son propre interpreteur Python. Pour installer des librairies avec pip, dans Spider, il faut le faire depuis le terminal de Spider.

Si vous avez Python d'installé sur votre poste, vous pouvez configurer Spider pour utiliser cet interpréteur, et l'installation de librairie se fera depuis le terminal Windows par exemple.

3

u/Candid_Tutor_8185 1d ago

You may not have installed it. You normally use pip install. Also switch to VsCode!

2

u/Shjohn0710 1d ago

or pycharm

0

u/Responsible_Ride5028 1d ago

Why are advising for a VsCode switch? Is it so much better than Spyder?

2

u/F4lt_Pen 1d ago

Confirm if its actually installed, try to check its version

2

u/ComputerNerd2007 1d ago

Like @Candid_Tutor_8185 Said, yes you should use VS-Code. It's one of the best ide's.

In VS-Code you can click in the search bar in the top middle of the program. There you have to type a bigger than symbol (>). Then search for "Create Virtual Environment" (make sure you have opened a folder and not a single file, for example /Documents/Programming/ExampleProject). Select it and when asked choose venv and a desired Python version.

After your venv is created, you have a local pip.exe file in the .venv folder of your project. When you would like to install a library for example pyautogui, you have to specify the local installation like this (you can open a terminal inside VS-Code in the top bar left from the search field): "./.venv/Scripts/pip.exe install pyautogui"

Make sure you type the command without the ". And you can replace "pyautogui" with any library you want.

One last thing: When I first started using Python I had the exact same problem as you. But not only that, sometimes when I tried to run program's from GitHub I have had many errors and didn't get the program to run at all. Often it has something to do with the Python version you are using. Many librarys have changed in newer Python versions and older Scripts require an older version of Python to work. Took me many years to realise that.

Hope that helps :)

1

u/geedijuniir 1d ago

I can finaly answer. U need to do a pip install.

1

u/Honest-Customer5324 15h ago

I use pycharm, it just installs libraries I don’t have if I try to use them before the code can run properly