雪豹上的 python 需要 32 位 libxml2 吗?

发布于 2024-08-23 03:16:06 字数 2309 浏览 3 评论 0原文

我在我的 sl mbp 上安装 scrapy 真是太麻烦了。它需要 libxml2,所以我开始安装它。从 macports 安装它似乎并没有拉下 python 绑定。

通过 scrapy 的说明从源代码安装它(此处)确实安装python 绑定,但是当我运行 'python -c "import libxml2"' 时,我得到一个体系结构不匹配:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "libxml2.py", line 1, in <module>
    import libxml2mod
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-    packages/libxml2mod.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-    packages/libxml2mod.so: mach-o, but wrong architecture

当我显式地将 libxml2 dll 构建为 32 位时,该错误消失,但由于其他原因,libxslt 不会构建库不是 32 位的。我害怕继续拉那根绳子。所以问题是 - python 仅限 32 位吗?我在这里做了什么蠢事吗?

编辑 - 这是 python 2.6

编辑 2 - 根据大众的需求,我在这里巩固了@Ned Deily 的精彩答案。所有的功劳都归功于他,我只是根据他的回复发布了我采取的步骤:

如果你一直在使用 mac 端口(并且没有通过它们安装任何你需要的其他东西),那么就用核武器攻击它们。

$ sudo rm -r /opt/local

将以下内容添加到 /opt/local/etc/macports/variants.conf 以防止使用以下命令下载整个 unix 库

+bash_completion +quartz +ssl +no_x11 +no_neon +no_tkinter +universal +libyaml -scientific

安装 macports 版本的 python

$ sudo port install python26

先决条件

sudo port install py26-libxml2 py26-twisted py26-openssl py26-simplejson py26-setuptools python_select
sudo python_select python26

安装 scrapy测试的 选择正确的 python:运行 $ which python,它应该显示类似于“/opt/local/bin/python”的内容,并且其本身应该是指向 /opt/ 的链接本地/bin/python2.6。

测试是否存在正确的体系结构:运行 file 'which python' (单引号应该是反引号,应该会输出(对于运行 10.6 的 intel mac):

/opt/local/bin/python2.6: Mach-O universal binary with 2 architectures
/opt/local/bin/python2.6 (for architecture x86_64): Mach-O 64-bit executable x86_64
/opt/local/bin/python2.6 (for architecture i386):   Mach-O executable i386

测试 libxml 是否安装成功

$ python -c 'import libxml2'

如果一切顺利, ,你应该没有得到任何输出。

安装 scrapy

sudo /opt/local/bin/easy_install-2.6 scrapy

穿过街道(穿着衣服),庆幸一切都完成了,感谢 ned 的详细回复。

i'm having a hell of a time installing scrapy on my sl mbp. it requires libxml2, so i set about installing that. installing it from macports doesn't seem to pull down the python binding.

installing it from source through scrapy's instructions (here) does install the python bindings, but when i run 'python -c "import libxml2"' i get an architecture mismatch:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "libxml2.py", line 1, in <module>
    import libxml2mod
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-    packages/libxml2mod.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-    packages/libxml2mod.so: mach-o, but wrong architecture

when i explicitly build the libxml2 dlls to be 32bit, that error goes away, but then libxslt won't build because of some other library not being 32 bit. i'm afraid to keep pulling on that string. so the question is - is python 32bit only? am i doing something stupid here?

edit - this is python 2.6

edit 2 - by popular demand, i'm consolidating @Ned Deily's awesome answer up here. all credit to him, i'm just posting the steps i took based on his response:

if you've been screwing around with mac ports, (and haven't installed anything else through them that you need), nuke them.

$ sudo rm -r /opt/local

add the following to /opt/local/etc/macports/variants.conf to prevent downloading the entire unix library with the next commands

+bash_completion +quartz +ssl +no_x11 +no_neon +no_tkinter +universal +libyaml -scientific

install the macports version of python

$ sudo port install python26

install the pre-reqs for scrapy

sudo port install py26-libxml2 py26-twisted py26-openssl py26-simplejson py26-setuptools python_select
sudo python_select python26

test that the correct python is selected: run $ which python, which should say something along the lines of '/opt/local/bin/python', and that in its own right should be a link to /opt/local/bin/python2.6.

test that the correct architectures are present: run file 'which python' (the single quotes should be backticks, which should spit out (for intel macs running 10.6):

/opt/local/bin/python2.6: Mach-O universal binary with 2 architectures
/opt/local/bin/python2.6 (for architecture x86_64): Mach-O 64-bit executable x86_64
/opt/local/bin/python2.6 (for architecture i386):   Mach-O executable i386

test that libxml installed successfully

$ python -c 'import libxml2'

if all is well, you should get no output.

install scrapy

sudo /opt/local/bin/easy_install-2.6 scrapy

run through the streets (fully clothed) rejoicing that everything is done. again, thanks to ned for the detailed response.

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

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

发布评论

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

评论(4

时光病人 2024-08-30 03:16:06

从回溯中的路径来看,您似乎已经安装并正在尝试使用 python.org python 2.6.4 (安装到 /Library/Frameworks/Python.frameworks ...)。该Python仅是32位的。默认情况下,在 10.6 上,MacPorts 尝试安装 64 位版本的软件包。您可以通过在 MacPorts 安装命令中指定 +universal 变体或将其添加到 /opt/local/etc/macports/variants.conf 来更改大多数 MacPorts 软件包的设置。但是,由于您需要各种软件包,如果您只需要为自己的计算机安装此软件包,您可能会发现使用 MacPorts 安装完整的 python2.6 64 位解决方案要容易得多。除了 scrapy 本身之外,您应该可以在那里找到几乎所有您需要的软件包。您需要修改 $PATH 以添加 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/opt/local/bin在其中包含 Python 的任何其他目录之前。像这样的东西应该可以工作(未经测试!):

sudo port selfupdate  # ensure you have the latest ports file information
sudo port install py26-libxml2 py26-twisted py26-openssl py26-simplejson py26-setuptools python_select
sudo python_select python26  # optionally make /opt/local/bin/python -> python2.6
sudo /opt/local/bin/easy_install-2.6 scrapy
# or install manually
cd /path/to/scrapy
sudo /opt/local/bin/python2.6 setup.py install

编辑:对于 10.6,由于在 64 位模式下缺乏 Tk 支持的一些问题,Tk 默认为您可能既不想要也不需要的 X11 版本。我将以下变体添加到 10.6 的 /opt/local/etc/macports/variants.conf (并非所有变体都适用于 python 和朋友):

+bash_completion +quartz +ssl +no_x11 +no_neon +no_tkinter +universal +libyaml -scientific

编辑:如果 MacPorts 安装正确,您应该在 10.6 上看到类似的内容:

$ ls -l /opt/local/bin/python2.6
lrwxr-xr-x  1 root  wheel  73 Oct 28 20:25 /opt/local/bin/python2.6@ -> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
$ file /opt/local/bin/python2.6
/opt/local/bin/python2.6: Mach-O universal binary with 2 architectures
/opt/local/bin/python2.6 (for architecture x86_64): Mach-O 64-bit executable x86_64
/opt/local/bin/python2.6 (for architecture i386):   Mach-O executable i386

如果您添加了 +universal 变体,否则您可能只会看到单个 x86_64 或 i386 架构。

使用相对路径时,请确保您的 shell $PATH 首先具有两个 MacPorts 目录:

$ echo $PATH
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin ...

您可能需要编辑 ~/.bash_profile 或其他 shell 文件以使该更改“永久”。如果您希望裸 python 命令引用 MacPorts Python,请确保运行上面显示的 python_select 命令。如果您仍然遇到问题,MacPorts 的一个好处是可以轻松删除并重新开始;只需:

$ sudo rm -r /opt/local

并下载 MacPorts 10.6 安装程序。但你真的不应该这样做。我认为解决这个问题并使其正常工作确实符合您的最大利益,因为它可能会在未来为您省去很多麻烦。

From the paths in your traceback, it appears you have installed and are trying to use the python.org python 2.6.4 (installed to /Library/Frameworks/Python.frameworks ...). That python is 32-bit only. By default on 10.6, MacPorts tries to install 64-bit versions of packages. You can change that for most MacPorts packages by specfying the +universal variant on your MacPorts install commands or by adding it to /opt/local/etc/macports/variants.conf. But, since you need a variety of packages, if you just need this for your own machine you'll likely find it much easier to just install a complete python2.6 64-bit solution using MacPorts. Other than scrapy itself, you should find nearly all of the packages you need already there. You'll need to modify your $PATH to add /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin and /opt/local/bin before any other directories with Python in them. Something like this should work (untested!):

sudo port selfupdate  # ensure you have the latest ports file information
sudo port install py26-libxml2 py26-twisted py26-openssl py26-simplejson py26-setuptools python_select
sudo python_select python26  # optionally make /opt/local/bin/python -> python2.6
sudo /opt/local/bin/easy_install-2.6 scrapy
# or install manually
cd /path/to/scrapy
sudo /opt/local/bin/python2.6 setup.py install

EDIT: For 10.6, due to some issues with lack of Tk support in 64-bit mode, Tk defaults to the X11 version which you probably neither want nor need. I add the following variants to /opt/local/etc/macports/variants.conf for 10.6 (not all of them are applicable to python and friends):

+bash_completion +quartz +ssl +no_x11 +no_neon +no_tkinter +universal +libyaml -scientific

EDIT: If MacPorts is installed properly, you should see something like this on 10.6:

$ ls -l /opt/local/bin/python2.6
lrwxr-xr-x  1 root  wheel  73 Oct 28 20:25 /opt/local/bin/python2.6@ -> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
$ file /opt/local/bin/python2.6
/opt/local/bin/python2.6: Mach-O universal binary with 2 architectures
/opt/local/bin/python2.6 (for architecture x86_64): Mach-O 64-bit executable x86_64
/opt/local/bin/python2.6 (for architecture i386):   Mach-O executable i386

That's if you've added the +universal variant, otherwise you may just see a single x86_64 or i386 architecture.

When using relative paths, make sure your shell $PATH has the two MacPorts directories first:

$ echo $PATH
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin ...

You may need to edit your ~/.bash_profile or other shell file to make that change "permanent". If you want the bare python command to refer to the MacPorts Python, make sure to run the python_select command shown above. If you are still having problems, a nice thing about MacPorts is it is easy to delete and start over again; just:

$ sudo rm -r /opt/local

and download the MacPorts 10.6 installer. But you really shouldn't have to do that. And I think it would really be in your best interests to get this fixed and working as it will likely save you lots of headaches in the future.

一袭白衣梦中忆 2024-08-30 03:16:06

我有一个小便条要贡献。在尝试跟进这篇文章时,我开始安装三个 Python:

  1. 默认 Apple Python 2.5.1 位于: /usr/bin/python
  2. 版本位于: /Library/Frameworks/Python.framework/Versions/2.7
  3. Macport 版本位于:/opt/local/bin/python2.6

我的麻烦是:

$ python

当我需要它使用 Macports 版本时,总是默认为 2.7。以下内容没有帮助:

$ sudo python_select python26

我什至删除了仅导致错误的 2.7 版本。

我发现我需要使用以下命令更改 Macports 版本的默认路径:

$ PATH=$PATH\:/opt/local/bin ; export PATH

然后重新启动端口等。

最后,我无法通过这些说明默认引用 scrapy-ctl.py 文件,所以我不得不直接引用 scrapy-ctl.py 文件

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py

更新

这篇文章的快速附录,其中包含创建链接的说明,找到Scrapy 网站(#2 和 #3)。

开始

sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy

从#2“将 Scrapy 添加到您的 Python 路径”和#3“使 scrapy 命令可用”

sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py /usr/local/bin/scrapy

I have a small note to contribute. While attempting to follow-along on this post, I began with three installs of Python:

  1. The default Apple Python 2.5.1 located at: /usr/bin/python
  2. A version located: /Library/Frameworks/Python.framework/Versions/2.7
  3. And a Macport version located: /opt/local/bin/python2.6

My trouble was that:

$ python

would always default to the 2.7 when I needed it to use the Macports version. The following did not help:

$ sudo python_select python26

I even removed the 2.7 version which caused only an error.

I figured out I needed to change the default path to the Macports version using the following:

$ PATH=$PATH\:/opt/local/bin ; export PATH

And then reinitiate the ports, etc.

Finally, I was not able to reference the scrapy-ctl.py file by default through these instructions so I had to reference the scrapy-ctl.py file directly

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py

UPDATE

A quick addendum to this post with instructions to create the link, found on the Scrapy site (#2 and #3).

Starting with #2, "Add Scrapy to your Python Path"

sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scrapy

And #3, "Make the scrapy command available"

sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py /usr/local/bin/scrapy
半步萧音过轻尘 2024-08-30 03:16:06

尝试安装但仍然很困难。
当我:

sudo /opt/local/bin/easy_install-2.6 scrapy

我收到错误消息并且它停止

AttributeError: 'NoneType' object has no attribute 'get'

时,我从头开始构建 Scrapy,效果很好。

然后我试试你写的

cd /path/to/scrapy
sudo /opt/local/bin/python2.6 setup.py install

/path/to/scrapy 在哪里?是:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py

还是

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Scrapy-0.8-py2.6.egg

在其他地方?

Trying to install but still struggling.
When I:

sudo /opt/local/bin/easy_install-2.6 scrapy

I get error message and it stops

AttributeError: 'NoneType' object has no attribute 'get'

Instead I build Scrapy from scratch which works fine.

Then I try what you write

cd /path/to/scrapy
sudo /opt/local/bin/python2.6 setup.py install

Where is /path/to/scrapy? Is that:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/scrapy-ctl.py

or

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Scrapy-0.8-py2.6.egg

or is somewhere else?

没有心的人 2024-08-30 03:16:06

感谢 @Ned Deily

如果您想在 OS X 10.6 上运行 Scrapy 0.8,这些步骤似乎有效。它使用 Macports 安装 Python 2.6,而不是与操作系统捆绑的安装。步骤假设 Macports 尚未安装。

从此处获取最新的 MacPorts 安装程序并安装:

http://www.macports.org/install.php

sudo port install py26-libxml2 py26-twisted py26-openssl py26-simplejson py26-setuptools python_select

sudo /opt/local/bin/easy_install-2.6 scrapy

将您的 ~.profile 更改为:

export     PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH

Credit to @Ned Deily

These steps seem to work if you want to run Scrapy 0.8 on OS X 10.6. It uses Macports install of Python 2.6 rather than the one bundled with the OS. Steps assume Macports is not installed yet.

Get latest MacPorts installer from here and install:

http://www.macports.org/install.php

sudo port install py26-libxml2 py26-twisted py26-openssl py26-simplejson py26-setuptools python_select

sudo /opt/local/bin/easy_install-2.6 scrapy

Change your ~.profile to:

export     PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文