开发者

Trouble installing MySQLdb for second version of Python

开发者 https://www.devze.com 2023-01-24 10:47 出处:网络
The context: I\'m working on some Python scripts on an Ubuntu server. I need to use some code written in Python 2.开发者_JAVA百科7 but our server has Python 2.5. We installed 2.7 as a second instance

The context: I'm working on some Python scripts on an Ubuntu server. I need to use some code written in Python 2.开发者_JAVA百科7 but our server has Python 2.5. We installed 2.7 as a second instance of Python so we wouldn't break anything reliant on 2.5. Now I need to install the MySQLdb package. I assume I can't do this the easy way by running apt-get install python-mysqldb because it will likely just reinstall to python 2.5, so I am just trying to install it manually.

The Problem: In the MySQL-python-1.2.3 directory I try to run python2.7 setup.py build and get an error that states:

sh: /etc/mysql/my.cnf: Permission denied

along with a Traceback that says setup.py couldn't find the file.

Note that the setup.py script looks for a mysql_config file in the $PATH directories by default, but the mysql config file for our server is /etc/mysql/my.cnf, so I changed the package's site.cfg file to match. I checked the permissions for the file, which are -rw-r--r--. I tried running the script as root and got the same error.

Any suggestions?


As far as I'm aware, there is a very significant difference between "mysql_config" and "my.cnf".

  • "mysql_config" is usually located in the "bin" folder of your MySQL install and when executed, spits out various filesystem location information about your install.

  • "my.cnf" is a configuration script used by MySQL itself.

In short, when the script asks for "mysql_config", it should be taken to literally mean the executable file with a name of "mysql_config" and not the textual configuration file you're feeding it. MYSQLdb needs the "mysql_config" file so that it knows which libraries to use. That's it. It does not read your MySQL configuration directly.

The errors you are experiencing can be put down to;

  1. It's trying to open the wrong file and running into permission trouble.

  2. Even after it has tried to open that file, it still can't find the "mysql_config" file.

From here, you need to locate your MySQL installation's "bin" folder and check it contains "mysql_config". Then you can edit the folder path into the "site.cnf" file and you should be good to go.


Are you sure that file isn't hardcoded in some other portion of the build process? Why not just add it to you $PATH for the duration of the build?

Does the script need to write that file for some reason? Does the build script use su or sudo to attempt to become some other user? Are you absolutely sure about both the permissions and the fact that you ran the script as root?

It's a really weird thing if you still can't get to it. Are you using a chroot or a virtualenv?

0

精彩评论

暂无评论...
验证码 换一张
取 消