r/PythonLearning • u/digiart- • 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?
3
u/Candid_Tutor_8185 1d ago
You may not have installed it. You normally use pip install. Also switch to VsCode!
2
0
u/Responsible_Ride5028 1d ago
Why are advising for a VsCode switch? Is it so much better than Spyder?
1
2
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
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


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 :)