0

I'm trying to look around on this issue but so far nothing I've found has fixed it. I am not that familiar with Python and I'm working with someone else's script. I am on Windows 10 (64-bit).

Executing this command: pip install mysql-python

And getting this error:

Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python27\lib\site-packages\pip\__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar  # noqa
File "C:\Python27\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "C:\Python27\lib\site-packages\pip\download.py", line 38, in <module>
from pip._vendor import requests, six
File "C:\Python27\lib\site-packages\pip\_vendor\requests\__init__.py", line 58, in <module>
from . import utils
File "C:\Python27\lib\site-packages\pip\_vendor\requests\utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "C:\Python27\lib\site-packages\pip\_vendor\requests\compat.py", line 7, in <module>
from .packages import chardet
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
David Mordigal
  • 399
  • 3
  • 19
  • Is there anything you don't understand? Isn't the error quite clear? – Vincent Savard Feb 08 '16 at 17:48
  • 1
    Did you try running `pip install urllib3`? – MattDMo Feb 08 '16 at 17:49
  • @MattDMo yes, same error – David Mordigal Feb 08 '16 at 17:50
  • @MattDMo: The error comes from pip, he'll have to install it from something other than pip. – Vincent Savard Feb 08 '16 at 17:51
  • @DavidMordigal try running `python -m pip install -U pip` and see if you get the same error. – MattDMo Feb 08 '16 at 17:53
  • @MattDMo `Requirement already up-to-date: pip in c:\python27\lib\site-packages` – David Mordigal Feb 08 '16 at 18:02
  • @DavidMordigal one more thing to try: `python -m pip install -U --force-reinstall pip`. This should reinstall pip and its dependencies from scratch. – MattDMo Feb 08 '16 at 18:14
  • @MattDMo okay, now I'm trying `pip install mysql-python`and it says `Cannot open include file: 'config-win.h': No such file or directory.` I downloaded an up to date version of the MySQL Connector/C and it still doesn't work. – David Mordigal Feb 08 '16 at 18:21
  • @DavidMordigal OK, here's what I should have suggested in the first place - download the appropriate `.whl` file for your version of Python [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python) - either 32- or 64-bit. Install it with `pip install filename.whl` and *hopefully* you should be all set. – MattDMo Feb 08 '16 at 18:47

2 Answers2

0

The python module that you are trying to install will probably require you to compile it which makes the task much harder for a newbie.

Instead, I would recommend you to use a pure-python module like https://github.com/PyMySQL/PyMySQL -- which is much easier to install because you do not have to compile it.

Usually I recommend anyone that is trying to work with databases in Python to use SQLAlchemy, mainly because this allows you to use a single interface when you deal with the database, one that does not depends on the database-driver being used.

Read the answer from python3 sqlalchemy pymysql connect string in order to get an idea about how to use pymysql via sqlalchemy.

Community
  • 1
  • 1
sorin
  • 161,544
  • 178
  • 535
  • 806
  • So after I install this, do I just change the line that says `import MySQLdb` to `import PyMySQL`? (On the script that I am trying to run). – David Mordigal Feb 08 '16 at 18:09
0
wget https://pypi.python.org/packages/3b/f0/e763169124e3f5db0926bc3dbfcd580a105f9ca44cf5d8e6c7a803c9f6b5/urllib3-1.16.tar.gz#md5=fcaab1c5385c57deeb7053d3d7d81d59
tar xvf urllib3-1.16.tar.gz  && cd urllib3-1.1
python setup.py install
Marthanda Anand
  • 196
  • 1
  • 6