1

I read some of the related topics and tried to implement those solutions to my situation but still I get the following error after this command :

(project2_env) Efe-MacBook-Air:MySQL-python-1.2.4b4 efe$ python setup.py build

The Error message is :

    Extracting in /var/folders/rv/vbf7xqh1601_xjkrn85w7hp00000gn/T/tmpptpsggg7
Traceback (most recent call last):
  File "/Users/efe/virtualenvs/downloads/MySQL-python-1.2.4b4/distribute_setup.py", line 143, in use_setuptools
    raise ImportError
ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 7, in <module>
    use_setuptools()
  File "/Users/efe/virtualenvs/downloads/MySQL-python-1.2.4b4/distribute_setup.py", line 145, in use_setuptools
    return _do_download(version, download_base, to_dir, download_delay)
  File "/Users/efe/virtualenvs/downloads/MySQL-python-1.2.4b4/distribute_setup.py", line 125, in _do_download
    _build_egg(egg, tarball, to_dir)
  File "/Users/efe/virtualenvs/downloads/MySQL-python-1.2.4b4/distribute_setup.py", line 99, in _build_egg
    _extractall(tar)
  File "/Users/efe/virtualenvs/downloads/MySQL-python-1.2.4b4/distribute_setup.py", line 486, in _extractall
    self.chown(tarinfo, dirpath)
TypeError: chown() missing 1 required positional argument: 'numeric_owner'

Edit: I reinstalled homebrew, then I run this following command. That is successfully installed.

brew install mysql

However, I cannot still import MySQLdb in python.

Efe Büyük
  • 135
  • 1
  • 3
  • 13

3 Answers3

1

As it is more complicated than the previous answer, i won't told you about the custom installation of python mysql.

Found this, the Jude's way :

Install mysql via homebrew, then you can install mysql python via pip.

xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
//don't know how to install mysql via homebrew, but it should be done here
pip install MySQL-python

https://stackoverflow.com/a/25356073/6660122

Community
  • 1
  • 1
technico
  • 1,192
  • 1
  • 12
  • 22
  • It turns out that I have already homebrew. Then, I tried `pip install MySQL-python` but now I got a different error which is : `Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/rv/vbf7xqh1601_xjkrn85w7hp00000gn/T/pip-build-yi9i16p8/MySQL-python/` – Efe Büyük Aug 06 '16 at 07:30
  • I uninstalled homebrew, then installed it again. After that, I tried this command again: `pip install MySQL-python` and I got a new different error: `-bash: /Users/efe/virtualenvs/project2_env/bin/pip: /Users/efe/virtualenvs/project2_env/bin/python3: bad interpreter: No such file or directory` – Efe Büyük Aug 06 '16 at 07:57
  • 1
    As said before, twice, you must install mysql via homebrew before installing python-mysql via homebrew. 3secs google search says : `brew install mysql` – technico Aug 06 '16 at 08:00
  • Sorry, my bad. I installed it via the command you said : `brew install mysql`. It is successful. Then I tried `pip install MySQL-python` again and got the same error that I wrote in my previous comment. I also tried to import MySQLdb in python but it didn't work. – Efe Büyük Aug 06 '16 at 08:12
  • At least your case is better documented for the other :') keep going! – technico Aug 06 '16 at 08:15
  • Yes, I hope so :) however my problem still continues :( after `brew install mysql` is successful, should `import MySQLdb` work? Because I tried it and didn't work. What should I do after this point? – Efe Büyük Aug 06 '16 at 08:21
  • You should update your question with a summary of our attempts, so other users will feel comfortable when looking at your problem. – technico Aug 06 '16 at 08:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120300/discussion-between-efe-buyuk-and-technico). – Efe Büyük Aug 06 '16 at 08:32
0

Taken from the Python2 doc, still relevant in 3.5 :

"Alternate installation: the user scheme

This scheme is designed to be the most convenient solution for users that don’t have write permission to the global site-packages directory or don’t want to install into it. It is enabled with a simple option: "

python setup.py install --user

Could help in your case.

Notice there are different scheme to use : --home, or --prefix and --exec-prefix, or --install-base and --install-platbase

technico
  • 1,192
  • 1
  • 12
  • 22
  • maybe try : `python setup.py install --home` . It seems you are facing a permission issue, but i don't know what to do more. – technico Aug 06 '16 at 06:44
0

Finally I found a solution for myself and by myself. I gave up using directly MySQLdb library and instead of that, I installed PyMySQL. By the way I had already installed MySQL Workbench before, so mysql server was already running.

Here is what I do step by step. I hope someone can get benefit from it.

1) Create a virtual environment:

virtualenv virt1

2) Make your virtual environment activated:

source virt1/bin/activate

3) Now, you are in your virtual environment. Install PyMySQL:

pip install PyMySQL

4) Now, try whether your MySQL connection is OK or not with a simple py executable:

#!/usr/bin/python

import pymysql.cursors

# Connect to the database
connection = pymysql.connect(host='localhost',
                             user='YourDBuserName',
                             password='YourDBpassword',
                             db='YourDBname',
                             charset='utf8',
                             cursorclass=pymysql.cursors.DictCursor)

try:
    with connection.cursor() as cursor:
        # Read a single record
        sql = "SELECT `id`, `name` FROM `YourTableName` WHERE `id`=%s"
        cursor.execute(sql, (1,))
        result = cursor.fetchone()
        print(result)
finally:
    connection.close()

5) You should see that your first row from the table appears on the screen.

Note: The part "import pymysql.cursors" could be tricky. First, I wrote as "import PyMySQL.cursors" and that didn't work!

Efe Büyük
  • 135
  • 1
  • 3
  • 13