简体   繁体   English

在雪豹上安装mysqldb

[英]Install mysqldb on snow leopard

I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. 我正在尝试开始在Django上使用Python我是专业的PHP开发人员,并被告知在我当前的apache和mysql设置上设置django和python但是我无法使用mysqldb模块让python工作,我必须遵循大约6种不同的指令,我正在运行雪豹并且本地安装了mysql它不是MAMP或类似的一部分。 Please can some tell me where I need to start and what steps I need to follew I would be most grateful. 请一些人告诉我我需要从哪里开始,以及我需要采取哪些步骤,我将非常感激。

Thanks 谢谢

On MAC OS X 10.6, Install the package as usual. 在MAC OS X 10.6上,照常安装软件包。 The dynamic import error occurs because of wrong DYLD path. 由于错误的DYLD路径而发生动态导入错误。 Export the path and open up a python terminal. 导出路径并打开一个python终端。

$ sudo python setup.py clean $ sudo python setup.py clean

$ sudo python setup.py build $ sudo python setup.py build

$ sudo python setup.py install $ sudo python setup.py install

$ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH $ export DYLD_LIBRARY_PATH = / usr / local / mysql / lib:$ DYLD_LIBRARY_PATH

$python $蟒蛇

import MySQLdb 导入MySQLdb

Now import MySQLdb should work fine. 现在导入MySQLdb应该可以正常工作。

You may also want to manually remove the build folder, before build and install. 您可能还希望在构建和安装之前手动删除构建文件夹。 The clean command does not do a proper task of cleaning up the build files. clean命令没有执行清理构建文件的正确任务。

I'd recomend installing macports (latest svn trunk) and installing mysql from there. 我建议安装macports(最新的svn trunk)并从那里安装mysql。

sudo port install mysql5-server sudo port安装mysql5-server

Download the MySQL-python-1.2.2 source 下载MySQL-python-1.2.2源代码

make sure /opt/local/lib/mysql5/bin is in your path or edit site.cfg to include: 确保/ opt / local / lib / mysql5 / bin在您的路径中或编辑site.cfg以包含:

mysql_config = /opt/local/lib/mysql5/bin/mysql_config

Comment out line 38 of _mysql.c 注释掉_mysql.c的第38行

// #define uint unsigned int

Then run: 然后运行:

sudo python setup.py install

should be all good. 应该都很好。

[Partial Answer] [部分答复]

You'll have more fun pulling out your teeth. 拉出你的牙齿会更有乐趣。 MySQL/Django/Mac is a disaster. MySQL / Django / Mac是一场灾难。 This is the farthest I've gotten: 这是我得到的最远的:

Get MySQLDB 1.2.3 Go into that and modify setup_posix.py: 获取MySQLDB 1.2.3进入并修改setup_posix.py

Change: 更改:

mysql_config.path = "mysql_config"

To (depending on the version number of your MySQL): 要(取决于您的MySQL的版本号):

mysql_config.path = "/usr/local/mysql-5.1.34-osx10.5-x86_64/bin/mysql_config"

python setup.py build python setup.py install python setup.py构建python setup.py安装

Here's a good article 这是一篇好文章

First and foremost, make sure that XCode is installed. 首先,确保安装了XCode Without XCode, many pieces of the built-in Apache2 server important to developers are missing; 没有XCode,很多对开发人员很重要的内置Apache2服务器都缺失了; most notably, the GNU Compiler Collection , which I would think to be requisite for MySQL bindings. 最值得注意的是GNU Compiler Collection ,我认为它是MySQL绑定的必备条件。

You could make your life a lot easier (especially on Lion) by just installing Mariadb instead: 你可以通过安装Mariadb来让你的生活变得更轻松(特别是在Lion上):

http://mariadb.org/ http://mariadb.org/

It's a drop-in replacement for MySQL and is plug&play on OSX. 它是MySQL的直接替代品,可以在OSX上实现即插即用。 The only thing you don't get is the MySQL system setting. 你唯一没有得到的是MySQL系统设置。

  1. Xcode was installed. Xcode已安装。

  2. Follow these instructions for setting up apache/php/mysql: 按照以下说明设置apache / php / mysql:

    http://maestric.com/doc/mac/apache_php_mysql_snow_leopard http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

  3. I installed the free 32-bit version of EPD (this is optional but I wanted numpy/scipy). 我安装了免费的32位版本的EPD(这是可选的,但我想要numpy / scipy)。

  4. Make sure you have these lines in your ~/.profile (the second line is only if you installed EPD): 确保在〜/ .profile中有这些行(第二行仅在您安装EPD时):

     export PATH=/usr/local/mysql/bin/:/usr/local/bin:/usr/local/sbin:$PATH export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}" 
  5. Downloaded mysqldb and run: 下载mysqldb并运行:

     python setup.py build sudo python setup.py install 
  6. Install the official release of Django or web2py. 安装Django或web2py的官方发行版。 Everything worked after that. 之后一切都有效。 You can try the "Writing Your First Django App, Part 1" to test it out where in settings.py use: 您可以尝试“编写您的第一个Django应用程序,第1部分”来测试settings.py使用的位置:

     DATABASE_ENGINE = 'mysql' DATABASE_NAME = 'Django Polls' DATABASE_USER = '*****' DATABASE_PASSWORD = '*****' DATABASE_HOST = '127.0.0.1' DATABASE_PORT = '3306' 
  7. I also use Navicat Lite and Sequel Pro for working with MySQL. 我还使用Navicat Lite和Sequel Pro来处理MySQL。

  8. Pydev is a nice IDE to use with Django. Pydev是一个很好的IDE与Django一起使用。

  1. Install the newest 64bit DMG version of MySQL. 安装最新的64位DMG版MySQL。 Remember to backup your databases if you already have MySQL installed. 如果已经安装了MySQL,请记住备份数据库。
  2. enter this line in terminal: 在终端输入此行:

    sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql sudo ln -s / usr / local / mysql / lib / usr / local / mysql / lib / mysql

  3. Edit the file setup_posix in the mysql-python installation directory. 编辑mysql-python安装目录中的setup_posix文件。

Change the line 改变线

mysql_config.path = "mysql_config"

to

mysql_config.path = "/usr/local/mysql/bin/mysql_config"
  1. Myslq-Python needs a 64bit Version of Python. Myslq-Python需要64位版本的Python。 The new Python 2.7 64bit version creates an alias in /usr/local/bin/python. 新的Python 2.7 64位版本在/ usr / local / bin / python中创建了一个别名。
  2. Enter the following lines in the mysql-python folder 在mysql-python文件夹中输入以下行

    sudo /usr/local/bin/python setup.py clean

    sudo ARCHFLAGS="-arch x86_64"

    sudo /usr/local/bin/python setup.py build

    sudo /usr/local/bin/python setup.py install

And finally try it out: 最后尝试一下:

python
import MySQLdb

One of the key things here is to make sure you're running both MySQL and the Python adaptor in 64 bit. 这里的关键之一是确保你以64位运行MySQL和Python适配器。 The default Python 2.6.1 install on Snow Leopard is 64 bit so you must install MySQL in 64 bit and build the MySQLdb adapter in 64 bit. Snow Leopard上的默认Python 2.6.1安装是64位,因此您必须以64位安装MySQL并以64位构建MySQLdb适配器。

  1. Make sure you have the latest Xcode installed 确保安装了最新的Xcode
  2. Install 64-bit MySQL from DMG - http://dev.mysql.com/downloads/mirror.php?id=401941#mirrors 从DMG安装64位MySQL - http://dev.mysql.com/downloads/mirror.php?id=401941#mirrors
  3. Download MySQL-python-1.2.3 from http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz下载MySQL-python-1.2.3
  4. Extract and make the following edit to site.cfg: 解压缩并对site.cfg进行以下编辑:

     mysql_config = /usr/local/mysql/bin/mysql_config 
  5. Then from your terminal run 然后从您的终端运行

     ARCHFLAGS="-arch x86_64" python setup.py build sudo python setup.py install 

You should then open a Python shell and type: 然后,您应该打开一个Python shell并键入:

import MySQLdb

If you don't get any errors you're golden. 如果你没有得到任何错误,那你就是金色的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM