Installing PyGame - ImportError: DLL load failed - python

My current version of Python is the newest 3.5 and the only available PyGame was for 3.2 (both PyGame and Python are 32-bit). I've scoured stackoverflow for a resolution and can't find any way to make this work. I've installed the PyGame easy installer and placed it in the directory where my Python install is, and in Visual Studio (I've also tried this in PyCharm as well as the standard Python IDE in command prompt), upon typing
import pygame or import sys, pygame
I'm presented with the error Import Error was
unhandled by user code - DLL load failed: The specified module could not be found.
My final solution is to uninstall Python 3.5 and install the version which matches PyGame.

This shouldn't have anything to do with Python version. You are missing a dynamic library (the DLL). This means that either the DLL is not on your system or Python can't find it. You should probably try the msi/exe installer for PyGame mentioned here, as it should install any dependencies. This would fix the issue if it is caused by the DLL being absent from your system.
It could also be caused by the libraries not being on PYTHONPATH. Search the error you received and you should see quite a few answers on fixing this.
If you're just getting started, you may want to look at a different library. There are likely quite a few game libraries for Python that can be installed with a simple pip install. You could then return to PyGame when you are more comfortable if you wanted.

get it from here: https://www.dropbox.com/s/hnmcaq1rf6zn7m3/pygame-1.9.2a0-cp34-none-win32.whl?dl=0
download it and install it by putting it in C:\python3.5\Scripts
then run pip3 install pygame-1.9.2a0-cp34-none-win32.whl
(this is for 3.4, but 3.5 works too)
it should work, and your error has nothing to do with the package, it's just that you do not have a DLL file, install it again from the website above

Related

How does one successfully download AND import pygame?

the problem:
as part of my studies, i have tried to download PyGame for my own independent project. I've currently downloaded 1.9.6, as well as currently owning IDLE version 3.8. i have imported it many times:
folder.
on one occasion , i placed it in its own separate folder with the coding file in another internal folder
when importing it into a new python script, the result was that there was "no module named Pygame", even though it was in a file containing the recent edition (this method was used successfully to download Tkinter).
I also tried making a python script outside the contained folder like this
this,too had the same result.
Any idea what exactly to do?
any more important information
The computer type is a MAC 10.13.6 and the IDE is IDLE. As previously mentioned, the downloaded version is version 1.9.6 and i have not a clue what how many bits my computer manages. Apologies that this is probably one of MILLIONS of the exact same question answered.I've tried at least 2 of these solutions.
First you need to make sure that you have pip installed. Type pip in your cmd (command prompt) and if you get no errors you are fine. If you have errors follow this link to get it. If you are stuck on that link - basically all you need to do is uninstall python and then when you are installing it again tick the box that says:
Add Python 3.5 to PATH
Now just finish installing python.
Next you need to install pygame with pip install pygame in your cmd - run it as administrator just to be safe. If you receive errors try updating pip with python -m pip install --upgrade pip. Now create and save a new python file. Import pygame in that file by using the code import pygame. The output should be:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Now you are free to code in pygame! I hope this helped.

ImportError: DLL load failed: The specified module could not be found. when importing cv2 in pycharm

I have installed opencv 3.4.0 and python 3.6.4 and pycharm. In pycharm I installed the numpy package. To add the python to pycharm, I copied the cv2.pyd file from the opencv to the python directory (in the DLLs folder and the site-packages folder). I get this error for the import cv2 line when I run the project: ImportError: DLL load failed: The specified module could not be found.
In the opencv folder, under python there is only a folder for 2.7, If this is the problem what could I do? I need to use a 3.+ version of python.
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
If the problem still persists try using Dependency walker to find out where specifically your problems stem from and then try fixing them individually.
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.
That should sort the problem, if it doesn't feel free to comment and maybe I can help more.

Import Error with scikit-surprise

When I ran the example code using scikit-surprise which is a package in python, it showed that "cannot import name similarities".
My operating system is windows 10 and python version is 2.7. When I tried to ran the exactly the same code on the school computer, it succeeded. The operating system in school computer is also windows 10. So it's not the problem of operating system.
I am very confused about what happened. When I commented out the "from .. import similarities as sims", there is another import error "Import Error: No module named optimize_baselines".
When I checked what was .optimize_baselines and similarities, I found they were all .c files.
So it seems that it cannot correctly import .c files. But how to deal with that?
You see import error as those packages are not installed in your home computer. So if those are public packages then you can download it via pip or easy_install.
I solved this problem by installing python3. I installed python2 using anaconda and failed to run the system. I found that the same situation happened on my school computer that the system cannot run with python2 but succeed using python3. I am sorry that I just found I typed "scikit learn" . It should be "scikit surpirse" which is a recommendation system. I guessed the problem was because the C++ compiler. But I am not sure about that.

Installing OpenCV - DLL load failed: %1 is not a valid Win32 application [duplicate]

I have a situation very much like the one at Error "ImportError: DLL load failed: %1 is not a valid Win32 application", but the answer there isn't working for me.
My Python code says:
import cv2
But that line throws the error shown in the title of this question.
I have OpenCV installed in C:\lib\opencv on this 64-bit machine. I'm using 64-bit Python.
My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7. This folder contains cv2.pyd and that's all.
My PATH variable: Path=%OPENCV_DIR%\bin;... This folder contains 39 DLL files such as opencv_core246d.dll.
OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11.
The solution at Error "ImportError: DLL load failed: %1 is not a valid Win32 application" says to add "the new opencv binaries path (C:\opencv\build\bin\Release) to the Windows PATH environment variable". But as shown above, I already have the OpenCV binaries folder (C:\lib\opencv\build\x64\vc11\bin) in my PATH. And my OpenCV installation doesn't have any Release folders (except for an empty one under build/java).
What's going wrong? Can I tell Python to verbosely trace the loading process? Exactly what DLL files is it looking for?
I noticed that, according to http://www.dependencywalker.com/, the cv2.pyd in C:\lib\opencv\build\python\2.7 is 32-bit, whereas the machine and the Python I'm running are 64-bit. Could that be the problem? And if so, where can I find a 64-bit version of cv2.pyd?
Unofficial Windows Binaries for Python Extension Packages
You can find any Python libraries from here.
Please check if the Python version you are using is also 64 bit. If not then that could be the issue. You would be using a 32-bit Python version and would have installed a 64 bit binaries for the OpenCV library.
Wow, I found yet another case for this problem. None of the above worked. Eventually I used python's ability to introspect what was being loaded. For Python 2.7, this means:
import imp
imp.find_module("cv2")
This turned up a completely unexpected "cv2.pyd" file in an Anaconda DLL directory that wasn't touched by multiple uninstall/install attempts. Python was looking there first and not finding my good installation. I deleted that cv2.pyd file and tried imp.find_module("cv2") again and python immediately found the right file and cv2 started working.
So if none of the other solutions work for you, make sure you use Python introspection to see what file Python is trying to load.
In my case, I have 64-bit Python, and it was lxml that was the wrong version--I should have been using the x64 version of that as well. I solved this by downloading the 64-bit version of lxml here:
https://pypi.python.org/pypi/lxml/3.4.1
lxml-3.4.1.win-amd64-py2.7.exe
This was the simplest answer to a frustrating issue.
I just had this problem. It turns out it was just because I was using an 64-bit version of the OpenCV file. I tried the x86 and it worked.
I had the same problem. Here's what I did:
I downloaded the pywin32 wheel file from here, then
I uninstalled the pywin32 module. To uninstall, execute the following command in a command prompt.
pip uninstall pywin32
Then, I reinstalled pywin32. To install it, open the command prompt in the same directory where the pywin32 wheel file lies. Then execute the following command.
pip install <Name of the wheel file with extension>
Wheel file will be like: piwin32-XXX-cpXX-none-win32.whl
It solves the problem for me.
I copied cv2.pyd file from /opencv/build/python/2.7/x86 folder instead of from /x64 folder to C:/Python27/Lib/site-packeges. I followed rest of the instructions provided here.
Added by someone else, not verified: I also copy file cv2.pyd to folder C:/Python27/Lib/site-packages/cv2. It works.
For me the problem was that I was using different versions of Python in the same Eclipse project. My setup was not consistent with the Project Properties and the Run Configuration Python versions.
In menu Project → Properties → PyDev, I had the Interpreter set to Python 2.7.11.
In Run Configurations → Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.
If your build system (CMake in my case) copies the file from <name>.dll to <name>.pyd, you will get this error if the original file wasn't actually a DLL file. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib.
I discovered this error by loading the pyd file in Dependency Walker and finding that it wasn't valid.
Update NumPy.
pip install numpy --upgrade
It works for me!
This one worked for me:
pip install -- pywin32==227
I faced the same issue when I uninstalled and reinstalled a different version of 2.7.x of Python on my system using a 32-bit Windows Installer. I got the same error on most of my import statements.
I uninstalled the newly installed Python, downloaded a 64-bit Windows installer, reinstalled Python again, and it worked.
So I had problems installing vtk under Windows (as I use Python 3.7, there isn't any binary available so far. Just for older Python versions pip install vtk is not working)
I did wrote Python in my cmd:
Python 3.7.3 on win32
So I now know I have Python 3.7.3 running on a 32 bit.
I then downloaded the correct wheel at VTK‑8.2.0‑cp37‑cp37m‑win32.whl
Next I installed that wheel:
pip install VTK-8.2.0-cp37-cp37m-win32.whl
Then I tested it and it worked:
python
import vtk
I experienced the same problem while trying to write code concerning speech-to-text.
The solution was very simple. Uninstall the previous pywin32 using the pip method:
pip uninstall pywin32
The above will remove the existing one which is by default for 32 bit computers. And install it again using
pip install pywin32
This will install the one for the 64 bit computer which you are using.
I had a similar issue while trying to run uvicorn,
Creating a new virtual environment and reinstalling the python packages worked
You can install opencv from official or unofficial sites.
Refer to this question and this issue if you are using Anaconda.
It has a very simple solution.
After installing opencv
place
cv2.pyd from C:\opencv\build\python\2.7\ **x64** to C:\Python27\Lib\site-packages
instead of, place cv2.pyd from C:\opencv\build\python\2.7\ **x86** to C:\Python27\Lib\site-packages
I got this error when trying to import MySQLdb.
What worked for me was to uninstall Python and then reinstall it.
I got the error after installing npm (https://www.npmjs.com/get-npm). One thing it did was install Python even though I already had it.
First I copied cv2.pyd from /opencv/build/python/2.7/x86 to C:/Python27/Lib/site-packeges. The error was
"RuntimeError: module compiled against API version 9 but this version of numpy is 7"
Then I installed numpy-1.8.0-win32-superpack-python2.7.exe and OpenCV works fine.
>>> import cv2
>>> print cv2.__version__
2.4.13
Please make sure that you have installed a Python 2.7.12 or below version. Otherwise you will definitely get this error.
Make sure the Oracle client is 64 bit installed if the OS is 64 bit.
Make sure the Microsoft Visual C++ compiler for Python 2.7 is 64 for bit for a 64 bit OS or 32 bit for 32 bit.
Note: If your OS is 64 bit, install all packages of 64 bit or if the OS is 32 bit, install the 32-bit package.
This has worked for me. I have tried different methods, but this was my best solution.
Open a command prompt and type the following;
pip install opencv-python
(Make sure your Internet connection is on.)
After that, try importing it again.
It could also be that your Anaconda version is 32 bit when it should be 64 bit.
If you are using pycharm I go to settings -> python interpretation and click the + button and search for the name on the list of python packages there
An image showing where to go when you want to install something
I found the solution. Maybe you can try to use the cmd window rather than the Anaconda prompt window to start your first Scrapy test.

how to install PyMouse on Windows

i am trying to use PyMouse plugin on windows 8.1 .
i used this code to import library :
from pymouse.windows import PyMouse
but this error shows :
from win32api import GetSystemMetrics
ImportError: No module named
'win32api'
where is the problem? i am not sure that i install the library fine ! can you show how to install it on windows ?
The win32api module is part of PyWin32, so you need to install that.
Meanwhile, you should be installing things with pip whenever possible. Some packages aren't pip-installable, or have incorrect requirements specs, but most packages, if you try to pip install them, will either automatically fetch their dependencies or complain that they're missing.
Also it looks like PyMouse's documentation is wrong, because it claims to only require ctypes (which comes with Python 2.6+), not PyWin32, on Windows. You may want to file a documentation bug with them.
However, it looks like the PyMouse you were using was abandoned at version 0.4 about 6 years ago. It was then picked up by someone else, but, as the README says, it was later merged into PyUserInput. So, you probably want to use that instead.
Note that PyUserInput correctly mentions the other dependencies in its README. It also checks them in its setup.py file. So hopefully, all you have to do is:
pip install PyUserInput
… and it will either pull in PyWin32 and pyHook, or complain that you have to go get them manually.

Categories