Reputation: 28
import os
import sys
import time
import threading
import pyautogui
But when I run the main.py module, it shows:
./main.py: line 5: import: command not found
./main.py: line 6: import: command not found
./main.py: line 7: import: command not found
./main.py: line 8: import: command not found
./main.py: line 9: import: command not found
pip3 install pyautogui
; it successfully installed.Requirement already satisfied: pyautogui in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (0.9.35)
BUT when I run the main.py, it still shows:
ImportError: No module named pyautogui
Python 3.8.8
I think there is something wrong with the download location, but I don't know how to fix it. Does anyone faced the similar problem?
Upvotes: 0
Views: 713
Reputation: 1007
How are you running your code? I think you are running it as executable without specifying the python path. So your OS is executing the file as a shell script. If your file name is code.py
, then you can run it as an executable file in Linux by first marking it as executable by user using this command: chmod +x code.py
and then run using ./code.py
. But to do this you need to add your python path at the top as a shebang line. Also specify what encoding to use in the next line as follows.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
You can find your python path using this command on Linux: which python
or which python3
. Or just simply run the code using python code.py
. In my Linux, python
is used for python 2 and python3
is for python 3 so depending on your OS the command may change.
Upvotes: 1