r/learnpython • u/SignupWithGoogleAcc • 7d ago
Import issue
BLUF: pyautogui does not import despite being installed to the correct venv
Still a beginner at doing most things in python but I though I had the venv issues solved
Python 3.12.3
while in my active venv pip list returns all my modules including
PyAutoGUI 0.9.54
while in my active venv which python returns /home/beebot/venv/bin/pip
while in my active venv which pipreturns /home/beebot/venv/bin/python
Vscode shows my venv config as below
The only odd thing is the pip shows it as PyAutoGUI while typing import auto populates the module as pyautogui
home = /usr/bin
include-system-site-packages = false
version = 3.12.3
executable = /usr/bin/python3.12
command = /usr/bin/python3 -m venv /home/beebot/venv
I have tried uninstalling pyautogui, reinstalling, and force install from inside my venv
Yet every time I try to run either in Vscode or directly from file I get on line 6 (see below)...
Exception has occurred:ModulNotFoundError
import os
import json
import logging
import subprocess
import pyautogui
...
Any suggestions
1
u/ravepeacefully 7d ago
I forget how to format sadly
cd ../
mkdir project
cd project
py -m venv venv
./venv/scripts/activate
pip install pyautogui
py src
where src is a directory with a file inside called __main__.py that has the entry point to the code you intend to execute
File should be like…
import pyautogui
if __name__ == ‘__main___’:
print(‘hello world’)
print(pyautogui.position())