为第二个版本的 Python 安装 MySQLdb 时遇到问题

发布于 2024-10-02 01:44:56 字数 640 浏览 1 评论 0原文

背景:我正在 Ubuntu 服务器上编写一些 Python 脚本。我需要使用一些用 Python 2.7 编写的代码,但我们的服务器有 Python 2.5。我们安装了 2.7 作为 Python 的第二个实例,因此我们不会破坏任何依赖于 2.5 的内容。现在我需要安装 MySQLdb 包。我认为我无法通过运行 apt-get install python-mysqldb 来轻松完成此操作,因为它可能会重新安装到 python 2.5,所以我只是尝试手动安装它。

问题:在 MySQL-python-1.2.3 目录中,我尝试运行 python2.7 setup.py build 并收到错误消息:

sh: /etc/mysql/my.cnf: 权限被拒绝

并且回溯表明 setup.py 找不到该文件。

请注意,setup.py 脚本默认在 $PATH 目录中查找 mysql_config 文件,但我们服务器的 mysql 配置文件是 /etc/mysql/my.cnf >,所以我更改了包的 site.cfg 文件以匹配。我检查了该文件的权限,即-rw-r--r--。我尝试以 root 身份运行脚本并得到相同的错误。

有什么建议吗?

The context: I'm working on some Python scripts on an Ubuntu server. I need to use some code written in Python 2.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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人练习一个人 2024-10-09 01:44:56

据我所知,“mysql_config”和“my.cnf”之间存在非常显着的差异。

  • “mysql_config”通常位于 MySQL 安装的“bin”文件夹中,执行时会输出有关安装

  • “my.cnf”是MySQL本身使用的配置脚本。

简而言之,当脚本请求“mysql_config”时,它应该被理解为名称为“mysql_config”的可执行文件,而不是您提供给它的文本配置文件。 MYSQLdb 需要“mysql_config”文件,以便它知道要使用哪些库。就是这样。它不会直接读取您的 MySQL 配置。

您遇到的错误可以归结为:

  1. 它试图打开错误的文件并遇到权限问题。

  2. 即使在尝试打开该文件后,仍然找不到“mysql_config”文件。

从这里,您需要找到 MySQL 安装的“bin”文件夹并检查它是否包含“mysql_config”。然后您可以将文件夹路径编辑到“site.cnf”文件中,然后就可以开始了。

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.

同展鸳鸯锦 2024-10-09 01:44:56

您确定该文件没有在构建过程的其他部分进行硬编码吗?为什么不在构建期间将其添加到 $PATH 中呢?

脚本是否由于某种原因需要写入该文件?构建脚本是否使用 su 或 sudo 来尝试成为其他用户?您是否完全确定权限以及您以 root 身份运行脚本的事实?

如果你仍然无法做到这一点,那真是一件很奇怪的事情。你使用的是 chroot 还是 virtualenv?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文