I've just started studying python and I really liked blessed looked like and wanted to give it a try.
I installed it using pip install blessed on the console and then I copied the following code from their site:
import os
import sys
print('Test run')
try:
from blessed import Terminal
except ModuleNotFoundError:
print('Could find the import :(')
After running the code, I receive the 'ModuleNotFoundError' exception.
How do I proper install blessed to avoid this error?
-- Edit
After some research turns out that py -m pip install blessed solved my problem.
Even though it is working now, what is the difference between using py -m pip install blessed and pip install blessed, which is what I used before?
Your edit suggests that your system's pip command runs pip for a different interpreter than the one you get by default when you run py (which is probably what you were using to run your script too). Each interpreter installed on your system will have its own set of installed modules, and it's own pip program to manage them. One interpreter usually can't use the modules installed for a different interpreter.
Related
After utilizing pip to install pyautogui successfully to my Python3.10 environment I'm utilizing in Visual Studio, I'm still getting this error when trying to simply import the library.
Warning (active) reportMissingImports Import "pyautogui" could not be resolved
I know it's installed to my correct repo, as I can see PyAutoGui (0.9.53) listed under packages of my active environment from the Solution Explorer. I also have th
I've tried a good few attempts to reinstall using pip and pip3 in separate attempts, but get "Requirement already satisfied" in return.
I'm new to Python and programming in general so any tips or assistance would be appreciated.
I've had similar issues like this before.
What python does is it looks in it's site-packages folder for the package, If you have multiple python versions installed sometimes the packages will be installed for one python version instead of the one you want.
This is what you can do.
Run
pip show pyautogui
This should output something like this:
/Users/<user>/.local/share/virtualenvs/place/lib/python3.8/site-packages
This is where your pyautogui module is installed at.
Now using python run this code.
import sys
print(sys.path)
Now the sys.path should contain the same site-packages path shown when we ran 'pip show pyautogui'
If sys.path does not contain the pyautogui site-packages path then that means pip installed pyautogui for the wrong python version.
I believe running pip with this command should install pyautogui to the correct python version.
python<version> -m pip install pyautogui
Example:
python3.8 -m pip install pyautogui
You can find out your python version by running:
python --version
I have looked at other similar questions but I got no answer.
I have installed pyautogui through pip install and I have checked using pip freeze and when I try to import this module I get the error "No module named 'pyautogui'".
I have also tried to restart the IDE that I am using (Pycharm) and I still don't know what is going on.
Does anyone have any ideas?
Before doing anything else, try restarting your IDE. Sometimes it's as simple as the module wasn't available when it started up.
Otherwise, it is possible that your pip installation is running under a different version of python than the IDE you are using. Some computers come with python pre-installed, and some IDEs might install a new version as a dependency, so you can end up with two (or more) different copies of python.
The easiest solution is probably going to be to install the package from within Pycharm, which will use the same copy of python: https://www.jetbrains.com/pycharm/guide/tips/install-and-import/#:~:text=PyCharm%20can%20do%20both.,according%20to%20your%20project%20styles.
Alternatively, you can try opening the python interpreter and importing the module there:
$ python
>>> import pyautogui
If that also fails, then installing pyautogui in the shell by running:
$ python -m pip install pyautogui
might solve it, if your IDE uses the same installation that is on your $PATH, but not the same as pip.
If that doesn't work, then you're going to need to figure out which python installations are being used where.
I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store.
I tried running a script in PowerShell: Bash *.sh
This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.
Then I received this error:
ModuleNotFoundError: No module named 'scipy'
My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.
I ran this command to update pip:
python3 -m pip install --upgrade pip
I ran this command to get some modules:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
I also tried this command just in case:
pip install scipy
and got the result:
Requirement already satisfied ...
I ran the command pip list to make sure scipy was in the list (and it was there).
Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.
I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!
From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location.
Try using these commands in both your terminal (cmd in windows) as well as in you bash script:
import sys
print(sys.path)
This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.
You can also refer to this: Python modules not found over terminal but on python shell, Linux
I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using
OR
you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.
I am attempting to use a small script to move my mouse slightly every minute or two to make the appearance that I am sitting at my desk (dont tell my boss please)
is anyone able to assist in why this might be happening?
from my command prompt I was able to successfully install pip install pyautogui
note, that: pip3 install autogui was not recognized
once I opened up pycharm, I ran the code, and got the below error:
ModuleNotFoundError: No module named 'pyautogui'
I also checked to make sure I had python 3 in command line using pip version = anaconda3\lib\site-packages\pip (python 3.7)
**full code below for reference
import pyautogui
import time
import sys
from datetime import datetime
pyautogui.FAILSAFE = False
numMin = None
if ((len(sys.argv)<2) or sys.argv[1].isalpha() or int(sys.argv[1])<1):
numMin = 1
else:
numMin = int(sys.argv[1])
while(True):
x=0
while(x<numMin):
time.sleep(60)
x+=1
for i in range(0,200):
pyautogui.moveTo(0,i*4)
pyautogui.moveTo(1,1)
for i in range(0,3):
pyautogui.press("shift")
print("Movement made at {}".format(datetime.now().time()))
https://github.com/Johnson468/Stay-Awake
for reference - i am using windows
You cannot import pyautogui from python 3 interpreter in pycharm because it is not installed.
When you ran pip install pyautogui you installed it on your python2.7 environment.
When you tried to installed it with pip3 you ran anaconda's pip (accordint to you error).
you can check which pip is used inside the CMD with the command where pip3.
If it is not found you can try running it like this: python -m pip but make sure you are running python3!
I highly recommend installing everything in venv virtual environment to make sure nothing is missing and you don't have any dependencies issues.
Or if you are new to python, uninstall all different instances and only keep one (probably python3 in your case), or edit you PATH in Windows
Furthermore I'm pretty sure when you are running pip from your console you are using another instance of it on your computer then the one you set as interpreter on pycharm, hence you couldn't use pip3 at all.
If none of the above helped, please add more details yo your question and I'll edit the answer.
Summary: You have a few instances of python installed on your computer (at least one of python2.7 and one of anaconda), when you run python or pip from the CMD if refers to the python2.7 one.
But when you chose an interpreter for you project in Pycharm you chose a python3 instance, which is obviously doesn't contain pyautogui.
Make sure you are using the right python instance when setting it up in Pycharm and when installing packages.
I answered this question recently: Problem with Python modules import on Mac
The issue might be that you don't have pip installed.
I know most Mac's have pip and Python pre-installed, but it wouldn't hurt to try: sudo easy_install pip
If this doesn't seem to be the issue, you might be running the pip install packageName in the wrong directory.
You will need to access your scripts folder in python and run the pip install packageName command in there. Here is a resource which should help you reach that directory: https://datatofish.com/install-package-python-using-pip/
This was answered for a Mac, but switching the commands to another OS shouldn't be hard. Just make sure pip is installed and that you're installing in the right directory.
I have used pip to install PyAudio, yet when I try to import it using import pyaudio, I get the following error message
ImportError : No module named PyAudio.
I tried to reinstall PyAudio, and it says that I already have it installed.
Please ensure you use import pyaudio, and not import PyAudio (as the error message suggests). Python is case sensitive.
This scenario can also be caused if you have multiple Python environments installed on your machine.
Some of the environment problems can be checked in the following way - open cmd and run:
where python
where pip
pip should be in the same directory as Python, under the "Scripts" folder.
If you find that the path to pip and the path to Python are completely different, some possible solutions are:
Change your current working directory in the cmd using cd. Make it point to the location of the correct pip. Then run pip install.
Remove the duplication of your Python environments. If you need more than one environment, use one of the available Python virtual environment solution (conda, virtualenv etc)