Getting Error while building mysql for python on Mac OS X El Capitan - mysql

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.

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

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

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!

Related

cant install pygame in pycharm

First of all, I'm new to programming. So,forgive me for my mistakes. I've installed pygame in python IDLE. But when I try to install it in pycharm, this happens:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
(venv) C:\Users\ARMAN\PycharmProjects\GAMES>pip install pygame
Collecting pygame
Using cached https://files.pythonhosted.org/packages/0f/9c/78626be04e193c0624842090fe5555b3
Complete output from command python setup.py egg_info:
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x86"?[Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\setup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\buildconfig\config.py", line 210, in main
deps = CFG.main(**kwds)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\buildconfig\config_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\buildconfig\download_win_prebuilt.py", line 302, in ask
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ARMAN\AppData\Local\Temp\pip-install-5f1r3j6w\pygame\
(venv) C:\Users\ARMAN\PycharmProjects\GAMES>py -m pip install -U pygame --user
Collecting pygame
Using cached https://files.pythonhosted.org/packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
Complete output from command python setup.py egg_info:
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x86"? [Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\setup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\buildconfig\config.py", line 210, in main
deps = CFG.main(**kwds)
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\buildconfig\config_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:\Users\ARMAN\AppData\Local\Temp\pip-install-nykuwxyw\pygame\buildconfig\downloa
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ARMAN\AppData\Local\T
(venv) C:\Users\ARMAN\PycharmProjects\GAMES>
I get an error. I've updated everything. Found a similar problem here:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000435070-Command-python-setup-py-egg-info-failed-with-error-code-1-whatever-package-I-try-to-install-.
But I can't understand the solution. So, please kindly help me.
This isn't my answer, but an answer from here:
Pygame docs recommends that you use Python version 3.6.1 or greater,
so I would suggest you to use the most recent non-beta version. Also,
some pygame wheels are not available to this version yet.
After the python installation make sure its added to your PATH
variable and try to install Pygame using this command given that you
are on windows:
py -m pip install -U pygame --user
If you get a PermissionError then
run the command prompt as administrator.
I hope this helps.

Integrating Apache Superset and Apache Drill

I installed Apache Drill through the link in the Drill Documentation. Apache Drill works fine. I also installed and got Apache Superset running using docker. Superset also works totally fine.
But my goal is to integrate Superset and Drill together. The only tutorial I was able to find was a tutorial from Dataist. When following this tutorial they ask us to add a database.
Since I am running both Drill and Superset in my local machine they ask us to type drill+sadrill://localhost:8047/dfs/test?use_ssl=False as the SQLAlchemy URI. They ask us to test the connection by pressing test connection.
When pressing test connection I get an error message as follows.
ERROR: {"error": "Connection failed!\n\nThe error message returned was:\nCan't load plugin: sqlalchemy.dialects:drill.sadrill", "stacktrace": "Traceback (most recent call last):\n File \"/home/superset/superset/views/core.py\", line 1755, in testconn\n engine = database.get_sqla_engine(user_name=username)\n File \"/home/superset/superset/utils/core.py\", line 132, in __call__\n value = self.func(*args, **kwargs)\n File \"/home/superset/superset/models/core.py\", line 911, in get_sqla_engine\n return create_engine(url, **params)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/__init__.py\", line 435, in create_engine\n return strategy.create(*args, **kwargs)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py\", line 61, in create\n entrypoint = u._get_entrypoint()\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/url.py\", line 172, in _get_entrypoint\n cls = registry.load(name)\n File \"/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py\", line 240, in load\n \"Can't load plugin: %s:%s\" % (self.group, name)\nsqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:drill.sadrill\n"}
Can someone figure out why I am getting this error. And also if there are any other tutorials to follow which give a better idea on how to set up Drill and superset.
I have encountered a similar issue while trying to connect elasticsearch. I guess the docker image you used was amancevice/superset. This issue cause because your image is not using the latest SQLAlchemy, SQLAlchemy-Utils packages. Upgrade or reinstall these packages to fix the issue.
To uninstall:
pip uninstall SQLAlchemy
pip uninstall SQLAlchemy-Utils
To install again (latest version):
pip install SQLAlchemy
pip install SQLAlchemy-Utils
I have reported this issue here https://github.com/amancevice/docker-superset/issues/158 maybe it get fixed with the upcoming images.

Python 3 Django - replace SQLite with MySQL (Linux Fedora)

I'm using Python 3, Django (1.11), on Linux fedora (23), (which use mariadb) and I'm trying to make it work with MySQL - instead of SQLite. And after about 8 hours of searching everything on google, I really doesn't know what to do..
I found a couple of times something with "python-mysql-connector" (something like this) but It's not really work.. (the installation)
I think that the main problem is that Django, is working with Python 3. However, Python 3 doesn't have "MySQLdb" library, (which Django trying to import) so if I edits this in the config file (of django)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
to this
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': '/etc/my.cnf', # i don't know if really necessary (mysql settings.. I think..)
},
}
}
so I get this error
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
(and of course more lines, but they doesn't important)
and
pip3 install mysqlclient
(which I found here Django 1.9 with Python 3.4 with MySQL support (Fedora) )
print this
[noam#localhost-localdomain ~]$ pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.7.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-18mq5vpo/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-18mq5vpo/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-18mq5vpo/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-18mq5vpo/mysqlclient/
[noam#localhost-localdomain ~]$
So how can I make it work? I'm really need that, and have no idea what to do..
I'll be glad for any help :)
Thanks, Noam

MySQL connector fails after switching from Python 2.7.X to 3.X

I installed the following mysql connector via pip:
pip install --allow-external mysql-connector-python mysql-connector-python
In my code I simply do a import mysql.connector as Connector and everything works fine. However, I used to use Python 2.7.X and now want to switch to Python 3.X (currently 3.5).
When I run my stuff under 2.7.X everything works fine. However, starting the same script with python 3.5 I get the following error message:
Traceback (most recent call last):
File "SWCrawler3.py", line 3, in <module>
import Configuration as cfg
File "/Users/Tom/SW/SWCrawler/SWCrawler/Configuration.py", line 4, in <module>
from database.MySQLConnection import MySQLConnection as MySQLConn
File "/Users/Tom/SW/SWCrawler/SWCrawler/database/MySQLConnection.py", line 6, in <module>
import mysql.connector as Connector
File "../mysql/connector/__init__.py", line 33, in <module>
from mysql.connector.connection import MySQLConnection
File "../mysql/connector/connection.py", line 128
except Exception, err:
^
SyntaxError: invalid syntax
Please note, that I wrote a wrapper file that I call MySQLConnection.
I had to intall the python3 packages of mysql-connector-python.
On my Mac I did the following:
brew install python3
pip3 install --allow-external mysql-connector-python mysql-connector-python
After that is worked. So use pip3.
On Windows with Python 3.5, I did something very close to toom's answer, that is :
pip3.5 install --allow-external mysql-connector-python mysql-connector-python

Error when trying to install Django CMS in virtualenv w/ MySQL on Mac OSX

I am getting the following error when I try to install django CMS with MySQL using virutalenv:
RuntimeError: maximum recursion depth exceeded
/Users/ethan/Sites/env/build/mysql-python/distribute-0.6.28-py2.7.egg
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/Users/ethan/Sites/env/build/mysql-python/setup.py", line 7, in <module>
use_setuptools()
File "distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "distribute_setup.py", line 125, in _do_download
_build_egg(egg, tarball, to_dir)
File "distribute_setup.py", line 116, in _build_egg
raise IOError('Could not build the egg.')
IOError: Could not build the egg.
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /Users/ethan/Sites/env/build/mysql-python
The command I am using for the install is the following:
env/bin/pip install --download-cache=~/.pip-cache -r reqs.txt
And the reqs.txt file looks like this:
django-cms==2.4.1
Django==1.5.1
django-classy-tags==0.4
South==0.8.1
html5lib==1.0b1
django-mptt==0.5.2
django-sekizai==0.7
six==1.3.0
Pillow==2.0.0
django-filer==0.9.4
cmsplugin-filer==0.9.5
django-reversion==1.7
mysql-python==1.2.4
I'm a novice to django (just going through the tutorial) and I cannot find anything in a search that seems to resolve this issue. Anyone have any ideas?
Change your requirement to mysql-python==1.2.5, I had the same problem on a CentOS 6.3 server.
mysql-python v. 1.2.4 has a hard dependency on distribute version 0.6.28. It might not be picking the right version of distribute.
Run this after the virtual env is activated:
easy_install distribute==0.6.28
and you should be good to proceed with
env/bin/pip install --download-cache=~/.pip-cache -r reqs.txt
change requirement to mysql-python==1.2.5 also worked for me on OS X mavericks with pip install