Unable to use LocateOnScreen function on Pyautogui (Python 3.9) - pyautogui

Here is my code:
import pyautogui
cord = pyautogui.locateOnScreen('chrome.png')
pyautogui.doubleClick(cord)'
However, I got this error:
I installed Pillow and imported PIL
I also installed opencv and numpy.
Through some research I realised it could be some site-package issues/ environment issues. I uninstalled and reinstalled python and updated the PATH.
please help I am at my wits end.

Known problem - i had it too. Maybe downgrade to 3.8 OR even 3.7.
I had to downgrade to 3.7 because a module in pyautoGUI made my script crash.

Related

SQLAlchemy NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:spanner

Problem
We're trying to connect to Cloud Spanner via SQLAlchemy version 1.3.23 and python-spanner-sqlalchemy. Using Poetry for dependency management, sqlalchemy-spanner has been added like so (this is how the project was set up):
sqlalchemy = "~1.3"
sqlalchemy-spanner = { git="https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy.git", tag="v0.1.0" }
When create_engine is called with
create_engine("spanner:///projects/my-project/instances/my-instance/databases/my-db")
I get the following error
class 'sqlalchemy.exc.NoSuchModuleError'>", "NoSuchModuleError(\"Can't load plugin: sqlalchemy.dialects:spanner\")
Attempts
Registry
I've tried adding (as seen in the conftest.py file in the python-spanner-sqlalchemy test package)
from sqlalchemy.dialects import registry
registry.register("spanner", "google.cloud.sqlalchemy_spanner", "SpannerDialect")
before create_engine is called, which leads to the following error:
class 'ModuleNotFoundError'>", "ModuleNotFoundError(\"No module named 'google.cloud.sqlalchemy_spanner'\")
This makes me think that the plugin dialect has not been correctly added since, in line 49 of setup.py, the connection for the dialect is made:
entry_points={
"sqlalchemy.dialects": [
"spanner = google.cloud.sqlalchemy_spanner:SpannerDialect"
]
},
Installing via python setup.py install
In the README for the spanner project, it says to clone the repo and install via python setup.py install. I performed this step, but am unsure how to import this into my current project or make my project aware of this library. I've never manually installed python packages before so, if anyone can provide any help here, I'd appreciate it.
What I did try:
install the library as per above
try to add the dependency via poetry : poetry add sqlalchemy-spanner. Got Could not find a matching version of package sqlalchemy-spanner
try to locate the library via pip : pip install sqlalchemy-spanner== which usually lists available package versions.
I'm not sure that either of the last 2 bullets actually check a local installation of a package. Not even really sure what I'm talking about here.
Update
So I was able to install the local version of python-spanner-sqlalchemy by using pip install /path/to/project, which works, but still having the same issues with loading the dialect.
I added an import for SpannerDialect in the code (in the Registry section) above with from google.cloud.sqlalchemy_spanner import SpannerDialect. PyCharm auto-completed this for me which indicates to me that the package is successfully installed and available. But I receive the ModuleNotFoundError for google.cloud.sqlalchemy_spanner when running.
I ran python in my project root directory and, from the repl, imported SpannerDialect with no errors.
Solution
To clarify, the solution #larkee provided worked regarding the updated repository URL.
As a note, we recently moved the repo from cloudspannerecosystem/python-spanner-sqlalchemy to googleapis/python-spanner-sqlalchemy.
I clarified why that worked in the comments to their answer
I have not tested the answer from #neondot42, but I have seen this brought up as well, so take a look there if you're having the same issue.
sorry for the late response. I was recently struggling with a similar problem. Sqlalchemy was unable to load the spanner dialect. I tried uninstalling and installing different versions with pip but nothing seemed to work.
At the end what did the trick was specifying the "driver" part of the database URL as "spanner" too. So the final URL looked like this:
spanner+spanner:///projects/project-id/instances/instance-id/databases/database-id
I am not entirely sure of why this appeared to be the solution for me, as all the documentation I could find on Google's end just showed that you could use only the "spanner:///..." to connect. Also I am not familiar with the inner workings of sqlalchemy and how it should detect other installed dialects. However, I hope this solution can help someone else.
I was able to replicate the error you are seeing by installing sqlalchemy but not having sqlalchemy-spanner installed at all:
pip install sqlalchemy==1.3
pip uninstall sqlalchemy-spanner
>>> from sqlalchemy import create_engine
>>> engine = create_engine(<url>)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:spanner
After I install sqlalchemy-spanner I am able to use SQLAlchemy without issue:
pip install git+git://github.com/googleapis/python-spanner-sqlalchemy.git#v0.1.0
>>> from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, inspect
>>> engine = create_engine(<url>)
>>> metadata = MetaData(bind=engine)
>>> table = Table(
... "TestTable",
... metadata,
... Column("user_id", Integer, primary_key=True),
... Column("user_name", String(16), nullable=False),
... )
>>> table.create()
>>> inspect(engine).get_table_names()
['TestTable']
>>>
Based on this, I think the issue is that sqlalchemy-spanner is not being installed. Unfortunately, I'm not familiar with Poetry for dependency management so I'm not sure exactly what is going wrong. As a note, we recently moved the repo from cloudspannerecosystem/python-spanner-sqlalchemy to googleapis/python-spanner-sqlalchemy. I am able to use either for the pip command but perhaps Poetry requires the newer one?

I'm having issues getting pygame to work as I don't understand how to assign path [duplicate]

I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing:
import pygame
I get following error message :
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
ImportError: No module named 'pygame'
>>>
I went through some of the questions related to this error but none of the solution helped.
I have 64 bit machine with Win7 OS
go to python/scripts folder, open a command window to this path, type the
following:
C:\python34\scripts> python -m pip install pygame
To test it, open python IDE and type
import pygame
print (pygame.ver)
It worked for me...
Here are instructions for users with the newer Python 3.5 (Google brought me here, I suspect other 3.5 users might end up here as well):
I just successfully installed Pygame 1.9.2a0-cp35 on Windows and it runs with Python 3.5.1.
Install Python, and remember the install location
Go here and download pygame-1.9.2a0-cp35-none-win32.whl
Move the downloaded .whl file to your python35/Scripts directory
Open a command prompt in the Scripts directory (Shift-Right click in the directory > Open a command window here)
Enter the command:
pip3 install pygame-1.9.2a0-cp35-none-win32.whl
If you get an error in the last step, try:
python -m pip install pygame-1.9.2a0-cp35-none-win32.whl
And that should do it. Tested as working on Windows 10 64bit.
I was trying to figure this out for at least an hour. And you're right the problem is that the installation files are all for 32 bit.
Luckily I found a link to the 64 pygame download! Here it is: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Just pick the corresponding version according to your python version and it should work like magic. The installation feature will bring you to a bright-blue screen as the installation (at this point you know that the installation is correct for you.
Then go into the Python IDLE and type "import pygame" and you should not get any more errors.
Props go to #yuvi who shared the link with StackOverflow.
open the folder where your python is installed
open scripts folder
type cmd in the address bar. It opens a command prompt window in that location
type pip install pygame and press enter
it should download and install pygame module
now run your code. It works fine :-)
I had the same problem and discovered that Pygame doesn't work for Python3 at least on the Mac OS, but I also have Tython2 installed in my computer as you probably do too, so when I use Pygame, I switch the path so that it uses python2 instead of python3. I use Sublime Text as my text editor so I just go to
Tools > Build Systems > New Build System and enter the following:
{
"cmd": ["/usr/local/bin/python", "-u", "$file"],
}
instead of
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
}
in my case. And when I'm not using pygame, I simply change the path back so that I can use Python3.
The current PyGame release, 1.9.6 doesn't support Python 3.9. I fyou don't want to wait for PyGame 2.0, you have to use Python 3.8. Alternatively, you can install a developer version by explicitly specifying the version (2.0.0.dev20 is the latest release at the time of writing):
pip install pygame==2.0.0.dev20
or try to install a pre-release version by enabling the --pre option:
pip install pygame --pre
Resolved !
Here is an example
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
try this in your command prompt:
python -m pip install pygame
I was getting the same error. It is because your version of Pygame is not compatible with your version of Python or Pydev. Go to this link and get the proper version of Pygame for your current version of Python. Ctrl F to find it faster or click on the word python in blue. up at the top. While you instal Pygame it should find the Python path by itself. At least mind did any ways. I run Pygame through Eclipse with Python 3.4.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Since no answer stated this:
Make sure that, if you are using a virtual environment, you have activated it before trying to run the program.
If you don't really know if you are using a virtual environment or not, check with the other contributors of the project. Or maybe try to find a file with the name activate like this: find . -name activate.
Install and download pygame .whl file.
Move .whl file to your python35/Scripts
Go to cmd
Change directory to python scripts
Type:
pip install pygame
Here is an example:
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
I just encountered the same problem and found that I am having multiple interpreters of the different versions installed in my system and pygame got installed in one of them when I installed it using command but in my IDE another interpreter was selected so this messed up my system, try to see if you are also having the same situation.
Just use this command in the terminal python3 -m pip install -U pygame --user
I am a quite newbie to python and I was having same issue. (windows x64 os)
I have solved, doing below steps
I removed python (x64 version) and pygame
I have downloaded and installed python 2.6.6 x86: https://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
I have downloaded and installed pygame (when installing, I have chosen the directory that I installed python): http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi
Works well :)
You don't need 64 bit Python on Win64 system, just install the 32bit versions of both Python and Pygame and they will work just fine (and there is a ton more modules for them anyways).
I’m using the PyCharm IDE. I could get Pygame to work with IDLE but not with PyCharm. This video helped me install Pygame through PyCharm.
https://youtu.be/HJ9bTO5yYw0
(It seems that PyCharm only recognizes a package; if you use its GUI.)
However, there were a few slight differences for me; because I’m using Windows instead of a Mac.
My “preferences” menu is found in: File->Settings…
Then, in the next screen, I expanded my project menu, and clicked Project Interpreter. Then I clicked the green plus icon to the right to get to the Available Packages screen.
I ran into the error a few days ago! Thankfully, I found the answer.
You see, the problem is that pygame comes in a .whl (wheel) file/package. So, as a result, you have to pip install it.
Pip installing is a very tricky process, so please be careful. The steps are:-
Step1. Go to C:/Python (whatever version you are using)/Scripts. Scroll down. If you see a file named pip.exe, then that means that you are in the right folder. Copy the path.
Step2. In your computer, search for Environment Variables. You should see an option labeled 'Edit the System Environment Variables'. Click on it.
Step3. There, you should see a dialogue box appear. Click 'Environment Variables'. Click on 'Path'. Then, click 'New'. Paste the path that you copies earlier.
Step4. Click 'Ok'.
Step5. Shift + Right Click wherever your pygame is installed. Select 'Open Command Window Here' from the dropdown menu. Type in 'pip install py' then click tab and the full file name should fill in. Then, press Enter, and you're ready to go! Now you shouldn't get the error again!!!
First execute python3 then type the command import pygame,now you can see the output
For this you have to install pygame package from the cmd (on Windows) or from terminal (on mac). Just type pip install pygame
.If it doesn't work for you, then try using this statement pip3 install pygame .
If it is still showing an error then you don't have pip installed on your device and try installing pip first.
make sure if you are on windows that your library directory is added to path
This may happen when pygame didn't installed, install the pygame first
pip
pip install pygame
if dont work update the PIP by goto python install folder and type
python -m pip install --upgrade pip
hope it work
Try this solution:
Type in to cmd (Windows):
C:\Users\'Your name'> pip install -U pygame
You should remove python -m, py -m, python3 -m before the pip
Also remove --user behind it.
It will said:
C:\Users\viait>pip install -U pygame
Defaulting to user installation because normal site-packages is not writeable
Collecting pygame
Downloading pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
---------------------------------------- 8.4/8.4 MB 1.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.1.2
Then test it in your IDE or cmd:
(CMD example)
C:\Users\viait>python
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.2 (SDL 2.0.18, Python 3.10.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
(IDE example)
import pygame
You can do this without any errors.
You could use
pip install pygame
but if you use IDE like PyCharm, then you could just either install it from Python Packages or use right click at the package name then left click on Show Context Actions then left click on Install package pygame
(Personally, I recommended using Python Packages for the package installing because it has documentation with it)
You gotta use Pycharm and install it in Terminal using pip install pygame and also after that enter Pycharm and hover on pygame in the "Import pygame" and in Pycharm it will tell you to download that and you can easily download it and enjoy your result
I was having the same trouble and I did
pip install pygame
and that worked for me!

Can't add pygame to pycharm?

Could someone help me with adding pygame to pycharm, I've tried going to pycharm setting and installing pygame in the project interpreter where the + sign is
Me going to setting and project interpreter
Me going to install pygame
But when installing this error appears
Me installing but the error occurs once done
More details on the error that occur
I've tried going to the command prompt and installing pygame there
This is what I did
But this error occurs
This error always occurs
I've tried looking at my environmental variable and followed a video, to see if my path is correct, which it is. Checked that I've updated pip and that tried running the command prompt both as an administrator and not. And even tried to uninstall and install different versions of python.
At this point I need help? If anyone could help, I would be truly grateful.
I finally figured it out, IF you're using python 3.8.0, python for whatever reason not allow you to install pygame or for any other package, in fact, you'll get the errors I got above in my question. The way to fix this is that you must uninstall python 3.8.0 and install an older version (I installed Python 3.7.5), this worked for me and allowed me to download pygame. I have no idea why you can't install packages in 3.8.0 might be a bug.
I had this problem a while ago too, you could try installing pygame through pycharm's virtual terminal. Pycharm's virtual terminal is located at the bottom of the screen. To open it, the button is on the bottom left next to the Python Console and to-do list. Inside pycharm's virtual terminal you should input,
pip install pygame
After this, you should be able to import pygame with ease. Hope this helps! Make sure to mark my answer as correct if it helps you out. Have a good day.

Using MPI4PY in FedoraScientific

Recently, I downloaded and installed Fedora Scientific 20 as I was
impressed with the list of included software. My interest in the software
is due to the inclusion of the MPI framework. I was able to compile and
execute a simple C program using mpicc and mpiexec. However, I need some
help using MPI4PY to call OpenMPI using Python code.
At the terminal prompt, if I try:
$ /lib64/openmpi/bin/mpiexec -n 2 python3 helloworld.py
The Traceback reports that an
ImportError: No module named 'mpi4py'
has been raised. The helloworld.py program was an example found online with
line 6 being from mpi4py import MPI.
Since Apper indicates that mpi4py has been installed for both Python2 and
Python3 for OpenMPI as part of the installation of Fedora Scientific, I'm not sure what might be wrong. Could somebody please advise as to how to use this package?
It sounds like there is something wrong with your environment. Perhaps mpi4py, since you have confirmed it is installed, is installed in a a strange place. Would setting PYTHONPATH help?
https://docs.python.org/2/using/cmdline.html#environment-variables

How to access MySQL from python

I've always used Xampp for db/ server purposes. I'm trying to use the same with my Python project but cannot seem to get it to work.
Error from Python Shell
import MySQLdb
ImportError: No module named 'MySQLdb'
I've been all around but nothing seems to work. I'm on windows 7, Python 3.3.
Please someone advise. Links that would resolve this quick will be greatly appreciated.
Update:
Please note that it seems MySQL-python does not support python3
From this discussion : https://groups.google.com/forum/#!topic/django-developers/8r_RVmUe5ys
Here is some connectors that can be used for mysql in Python 3.x:
https://github.com/davispuh/MySQL-for-Python-3 / https://github.com/clelland/MySQL-for-Python-3
http://www.pymysql.org/
https://github.com/farcepest/moist
https://pypi.python.org/pypi/mysql-connector-python/1.0.9
pip install MySQL-python
Run this in your Windows console or Linux terminal, and this problem should disappear.