I'm trying to install ibm-db into a virtual environment with Python running on an IBM i. I'm running into the following exception about limits.h no such file or directory. All the other similar questions I've found were either on Linux or MacOS, so not sure how to resolve this on an IBM i.
I also tried doing this at the system level without a virtual environment and ran into the same problem. I'm trying to install ibm-db version 3.0.2 (latest at time of this question) and that could be part of the problem. If I list the system installed packages, there is a version 2.0.5.12 of ibm-db already installed.
My IBM i is at release V7R2.
Update 2021-01-15 # 1:42PM
This seems to not be limited to the latest version of ibm-db. I tried installing a few other versions, right down to 2.0.5 and I get the same error. So it sounds like something is missing in the environment.
Despite a few mentions of IBM i (or i5) in the main ibm-db project, it really doesn't have proper support for being run from IBM i. (It may be the case that connecting to IBM i from some other platform still works; I have not verified this.) If you want to use ibm-db with IBM's Python for PASE, you need to be using Kevin Adler's fork. See the issue establishing this.
The most straightforward way to do this is via the RPMs (installed via yum directly, or the Access Client Solutions GUI). It looks like you already have the latest version of this installed (2.0.5.12 as of this writing).
Further, if you want to use virtual environments (which is a good idea), your best bet is to use the --system-site-packages option, so that it finds the RPM-installed one.
Finally, if you are not tied to ibm-db, the recommended way to connect in a PEP-249-ish way is through ODBC. There is now sufficient support for ODBC on PASE that you can actually develop and test code connecting from your PC to IBM i using pyodbc, and then just use that exact same code on PASE.
I've looked at other similar issues, but all my paths seem to be fine. I tried to install the python mysql library in conda so I could use it. To all metrics, it seems installed and recognized in the Pycharm interpreter, and when running conda list, I see mysql as an installed library, yet any time I try to import it, I get a ModuleNotFoundError. See below for a sample:
To isolate the issue, I chose to install another well known package that was not previously on my env, tenserflow, here's the results of that:
Evidently the issue is with the mysql library, since tensorflow installed and functioned as expected, meaning this isn't an issue with the interpreter, or an incorrect python path, or probably even conda.
I'm at a loss to what the issue is. I have mysql server installed, though that shouldn't matter, and I only have one environment. I'm trying to connect to a db, and have never used any mysql libraries on Python, so if there's others can be recommended, I have no preference, I just want my db!
Thanks in advance!
You have only installed the c library mysql, not the python library that you were looking for.
You need to do
conda install -c conda-forge mysql-connector-python
which will install the mysql python module that you are looking for
I have MySQL and Python on my computer. I want to write statements in Python scripts that extract (SELECT) data from a MySQL schema and other statements that INSERT data into MySQL tables.
My version of Python is 2.7, and I installed it via Anaconda.
From what I have read it would be appropriate to use the module “import MySQLdb”. But before doing so, I would need to download and install some code that supports this module. The only code that I have found that might work are mysql-connector-python-2.1.5-py2.7-winx64.msi or mysql-connector-python-2.1.5-py2.7-win32.msi.
When I execute either of those MSI’s, the result is a pop-up with an error message: “Python 2.7 not found. We only support Python installed using the Microsoft Windows Installer (MSI) downloaded from http://www.python.org/download/. Please check the Connector/Python manual on http://dev.mysql.com/doc/ for more information."
I skimmed the Connector/Python manual to find more information about the incompatibility; no luck. I checked the PATH on my computer; it does include c:\users\sncole\Anaconda, and python.exe does reside in this folder.
Is there any way that I can use one of the MSI’s mentioned above, or is there another download that I can use for Python that was installed via Anaconda?
Assuming that you have installed Anaconda correctly, conda should be in your path. Then you can install mysql connector by typing
conda install -c anaconda mysql-connector-python
My various searches seem to come up with very old posts or a mention of how to do this under cygwin. I had python 3.5 installed and then installed Anaconda3. I have python 3.5 (Cpython) installed in my user directory. I tried changing the order of how things appear in my Windows Environment Variables path, so that I could try both the Anaconda version of Python and the other version of python that I have.
Currently, I am a bit confused as to the package name that I should use. Is it python-mysqldb, or MySQLdb, or mysqldb, mysqlclient. I believe that when I had Anaconda3 in my global path (and the other version of python in my user path), I was able to install mysqlclient.
Initially, I am just trying to follow a tutorial from a training site that covers databases and uses peewee.
So, can the mysql driver for peewee be installed for python3? Or on Windows specifically?
It is easy enough to use sqlite3, one doesn't use that in production, is that right?
Can someone help me? Provide some guidance?
Also, one source of confusion is when other forms of installation of a python package are listed in the google results (many point to stack overflow), such as using easy_install, or cloning something from git. When I see instructions that are from 2010 and they reference easy_install, I had been thinking that now we can just use pip instead? Also, sometimes I see use of the conda command. Does that work the same as pip?
Thanks in advance,
Bruce
You could use pymysql. "The goal of PyMySQL is to be a drop-in replacement for MySQLdb". Check the docs here. Install the following libraries
pip install mysqlclient pymysql
Once these libraries are installed, just add the lines in the manage.py file in your project and use the database settings for mysql.
import pymysql
pymysql.install_as_MySQLdb()
Now any files that import MySQLdb will work.
I am finding it difficult to use MySQL with Python in my windows system.
I am currently using Python 2.6. I have tried to compile MySQL-python-1.2.3b1 (which is supposed to work for Python 2.6 ?) source code using the provided setup scripts. The setup script runs and it doesn't report any error but it doesn't generate _mysql module.
I have also tried setting up MySQL for Python 2.5 with out success. The problem with using 2.5 is that Python 2.5 is compiled with visual studio 2003 (I installed it using the provided binaries). I have visual studio 2005 on my windows system. Hence setuptools fails to generate _mysql module.
Any help ?
Download page for python-mysqldb. The page includes binaries for 32 and 64 bit versions of for Python 2.5, 2.6 and 2.7.
There's also discussion on getting rid of the deprecation warning.
UPDATE: This is an old answer. Currently, I would recommend using PyMySQL. It's pure python, so it supports all OSes equally, it's almost a drop-in replacement for mysqldb, and it also works with python 3. The best way to install it is using pip. You can install it from here (more instructions here), and then run:
pip install pymysql
This may read like your grandpa givin advice, but all answers here did not mention the best way: go nd install ActivePython instead of python.org windows binaries. I was really wondering for a long time why Python development on windows was such a pita - until I installed activestate python. I am not affiliated with them. It is just the plain truth. Write it on every wall: Python development on Windows = ActiveState!
you then just pypm install mysql-python and everything works smoothly. no compile orgy. no strange errors. no terror. Just start coding and doing real work after five minutes.
This is the only way to go on windows. Really.
As Python newbie learning the Python ecosystem I've just completed this.
Install setuptools instructions
Install MySQL 5.1. Download the 97.6MB MSI from here You can't use the essentials version because it doesnt contain the C libraries.
Be sure to select a custom install, and mark the development tools / libraries for installation as that is not done by default. This is needed to get the C header files.
You can verify you have done this correctly by looking in your install directory for a folder named "include". E.G C:\Program Files\MySQL\MySQL Server 5.1\include. It should have a whole bunch of .h files.
Install Microsoft Visual Studio C++ Express 2008 from here This is needed to get a C compiler.
Open up a command line as administrator (right click on the Cmd shortcut and then "run as administrator". Be sure to open a fresh window after you have installed those things or your path won't be updated and the install will still fail.
From the command prompt:
easy_install -b C:\temp\sometempdir mysql-python
That will fail - which is OK.
Now open site.cfg in your temp directory C:\temp\sometempdir and edit the "registry_key" setting to:
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1
now CD into your temp dir and:
python setup.py clean
python setup.py install
You should be ready to rock!
Here is a super simple script to start off learning the Python DB API for you - if you need it.
I found a location were one person had successfully built mysql for python2.6, sharing the link, http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe
...you might see a warning while import MySQLdb which is fine and that won’t hurt anything,
C:\Python26\lib\site-packages\MySQLdb__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
What about pymysql? It's pure Python, and I've used it on Windows with considerable success, bypassing the difficulties of compiling and installing mysql-python.
You're not the only person having problems with Python 2.6 and MySQL (http://blog.contriving.net/2009/03/04/using-python-26-mysql-on-windows-is-nearly-impossible/). Here's an explanation how it should run under Python 2.5 http://i.justrealized.com/2008/04/08/how-to-install-python-and-django-in-windows-vista/
Good luck
The precompiled binaries on http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python is just worked for me.
Open MySQL_python-1.2.5-cp27-none-win_amd64.whl file with zip
extractor program.
Copy the contents to
C:\Python27\Lib\site-packages\
On Python 3.4 I've installed mysqlclient from http://www.lfd.uci.edu/~gohlke/pythonlibs/ with pip install mysqlclient and it's working.
You can try to use myPySQL. It's really easy to use; no compilation for windows, and even if you need to compile it for any reason, you only need Python and Visual C installed (not mysql).
http://code.google.com/p/mypysql/
Good luck
There are Windows binaries for MySQL-Python (2.4 & 2.5) available on Sourceforge. Have you tried those?
Because I am running python in a (pylons/pyramid) virtualenv, I could not run the binary installers (helpfully) linked to previously.
I had problems following the steps with Willie's answer, but I determined that the problem is (probably) that I am running windows 7 x64 install, which puts the registry key for mysql in a slightly different location, specifically in my case (note: I am running version 5.5) in: "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.5".
HOWEVER, "HKEY_LOCAL_MACHINE\" cannot be included in the path or it will fail.
Also, I had to do a restart between steps 3 and 4.
After working through all of this, IMO it would have been smarter to run the entire python dev environment from cygwin.
If you are looking for Python 3.2 this seems the best solution I found so far
for Python 2.4 - 3.2 PyMySQL
for Python 2.3 - 2.6 MySQL for Python
Source: http://wiki.python.org/moin/MySQL
You might want to also consider making use of Cygwin, it has mysql python libraries in the repository.
You can also use pyodbc with the MySQL Connector/ODBC to use MySQL on Windows. Unixodbc is also available to make the code compatible on Linux. Pyodbc uses the standard Python DB API 2.0 so if you stick with that switching between MySQL/PostgreSQL/SQLite/ODBC/JDBC drivers etc. should be relatively painless.
upvoted itsadok's answer because it led me to the installation for python 2.7 as well, which is located here: http://www.codegood.com/archives/129
Got sick of the installation troubles with MySQLdb and tried pymysql instead.
Easy setup;
git clone https://github.com/petehunt/PyMySQL.git
python setup.py install
And APIs are pretty much the same.