Unable to install MySQLdb on Python 2.7 on MacOS Mojave - python

I used to create a big program in Python 2.7 that uses MySQLdb a long time ago. I developed it both on Mac OS and PC.
I just had to re-refomat my Mac and I'm now on Mojave. Whereas I have been able in the past to easily install MySQLdb, I'm unable to do so now.
I've tried all that was available on the forums with no success.
PIP, easy-install, Brew and many other solutions that I forgot.
Even "easy_install MySQL-python" found in Installing MySQLDB on Python 2.7.3 under CentOS gave me an error ending by :
EnvironmentError: mysql_config not found
I expect to be able to "import MySQLdb" in my Python code, but MySQLdb isn't installed and so "no found"
Thanks a lot for your help.

So, you either have upgrade your MySQL Version to a 64Bit Version, get the newest MySQL-Python Connector, update your code and use this instead of MySQLdb. Which is the safest and best solution, but u have to put in some work (no problem if your code isn't that long anyways...)
https://dev.mysql.com/downloads/connector/python/
https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
import mysql.connector
Second chance is, staying with your old 32Bit MySQL Version (for Example 5.6.20 32Bit), and still using the same old MySQL Python Connector (For Example Mysql-Python Connector 1.2.3 in 32Bit, found on the Mysql Download page aswell) you used before. There will be some popup errors, such as a few Libraries are out of date and probably not compatible anymore, but it's working.

Related

IBM Db2 SQL Alchemy adapter -- issue with client driver [duplicate]

After updating to Mac Catalina (version 10.15.6), I had to re-install Python and all dependent modules.
My problem now is that when adding the module ibm_db, I get the following error message when trying to run my program:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_db.cpython-37m-darwin.so, 2): Symbol not found: ___cxa_throw_bad_array_new_length
Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/clidriver/lib/libdb2.dylib
Expected in: /usr/lib/libstdc++.6.dylib
in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/clidriver/lib/libdb2.dylib
I am using PyCharm 2018.3.7 (CE).
Anyone that has seen this, and have a fix for this?
The problem is due to older version of /usr/lib/libstdc++.6.dylib installed in your system. New installation of ibm_db is looking for newer version of libstdc++.6.dylib.
There are two quick solution for it. You can use either one:
Install new gcc of version >= 8 in your system and set environment variable to use it so that libstdc++.6.dylib from new version of gcc should get picked up instead of existing old one.
OR,
export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/clidriver/lib
Thanks.

pyodbc module does not work with Python3

I have just transitioned to a Mac (from Win) and I cannot find the proper way to make a script work (it did on Win).
I am using import pyodbc on the first line and I get the "No module .." error.
Later Edit: I changed the first line to import pypyodbc
If I enter the workspace in the preexistent python version (2.7.10) I can import the module but the script fails with:
pyodbc.Error: ('00000', '[00000] [iODBC][Driver Manager]dlopen({SQL Server}, 6): image not found (0) (SQLDriverConnect)')
I want to use python3 anyway.
If I enter python3, when trying to import the module I get an error.
My main problem is that I an not sure how to find where the problem is. Can anyone help with this?
Later Edit
It worked if I used pypyodbc instead of pyodbc. It imports the module and the only thing left to solve is the decoding part: UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 0-1: truncated data
Module pyobdc is distributed for Python3. You can check that on its PyPi page.
Did you actually install it for Python3?
Python packages are installed separately for each Python instance on your machine. (In fact, you may even use virtual environments to create multiple environments for one Python installation, which can be useful if you need to run several applications with dependencies on different versions of the same library.)
To install a package using pip for Python3 on a Mac with also Python2 installed, see this question.
Edit: installation issue
Your problem seems to be related to this issue in pyodbc.
The fix is in master but not released on Pypi. You may try to install the latest version from master branch.
Should be:
pip install git+https://github.com/mkleehammer/pyodbc#master

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.

Verify thread-safety MySQLdb (Python) prior to Trac installation

I'm trying to install Trac manually for the first time. I don't want to use a one-click-installer like Bitmani, I want to learn how to install Trac manually, so I'm following the instructions carefully. I'm installing it in a Windows localhost for now, before installing it in a Linux environment.
As I follow the instructions carefully, I needed to install Python+MySQLDb, and I read this:
thread-safety is important
(...) verify that it is thread-safe by calling MySQLdb.thread_safe() from a standalone Python script (i.e., not under Apache). If the stand-alone test reports that MySQLdb is indeed thread-safe (...)
I've just installed MySQLDb 1.2.4 and I'd like to verify this. I've Googled but I haven't found an example about this, and I have no idea about Python. How can I verify if I've got a thread-safe installation?
Run this command. If you get 1 in the output, your installation is threadsafe.
python -c "import MySQLdb ; print MySQLdb.thread_safe()"

No module named psycopg2

I have Django project which uses postgresql 9. I installed psycopg2 and when I run project I receive 'Error loading psycopg2 module: dll load failed'. I met this issue for the first time. I have windows 7 x64 with python2.7. How can I solve this one?
I had the same problem, it was that psycopg2 does not install well in Windows with _easy_install_, I followed the instructions on the follow SO answer:
Installing psycopg2 (postgresql) in virtualenv on windows
You need to manually install the psycopg2 exe file:
psycopg2-2.4.2.win-amd64-py2.7-pg9.0.4-release.exe
I know this is going to haunt me again or as nwcell puts it:
Every time I need to set up psycopg2 on windows, I wind up wanting to shoot something.
I actually have a machine with it working and I've been at pains to setup another machine. I installed Python 3.8 and the old PC has 3.7.4. The main difference was the file:
C:\project\venv\Lib\site-packages\psycopg2_psycopg.cp37-win32.pyd
On the new PC it was showing as AMD64. I eventually uninstalled 3.8 and reverted back to 3.7.4, then I copied the files from the old PC to the new and then I hit this error:
https://stackoverflow.com/a/37819509/495455
Going to a WayBackMachine version of the stickpeople:
https://web.archive.org/web/20191003103502/http://www.stickpeople.com/projects/python/win-psycopg/
I didn't install the exe, I simply did a pip install -Iv psycopg2-binary==2.8.4 at which point it started working. So I'm thinking the latest version doesn't work, for me 2.8.4 still works: https://pypi.org/project/psycopg2/#files
It's something to do with x64 as everything I tried with AMD64 didn't work and I spent ages on it.

Categories