python在mac os 10.10.1上安装lxml

时间:2015-05-23 07:14:39

标签: python macos python-2.7 scrapy lxml

我买了一个新的macbook,我对mac os很新。但是,我在互联网上阅读了很多关于如何安装废料的信息

我做了所有事情,但我在安装lxml

时遇到了问题

我在终端上试过这个

 system.time({DT1 <- as.data.table(m1)
   DT2 <- as.data.table(m2)
   for(j in 1:ncol(DT1)){
   set(DT1, i=NULL, j=j, value=DT2[[2]][fmatch(DT1[[j]], DT2[[1]])])
   }
  })
 #  user  system elapsed 
 # 0.108   0.005   0.114 

并且很多东西开始下载并且终端上写了很多文字,但是终端上的红色显示了这条错误消息

pip install lxml

现在当我用lxml调用scrapy spider这个词时,我收到了这条错误信息

1 error generated.

error: command '/usr/bin/clang' failed with exit status 1

----------------------------------------
Cleaning up...
Command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools, tokenize;__file__='/private/var/folders/rd/fxgsy46j3l77f6l9h_hv2fjm0000gn/T/pip_build_mycomputername/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/rd/fxgsy46j3l77f6l9h_hv2fjm0000gn/T/pip-WvDTPQ-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/rd/fxgsy46j3l77f6l9h_hv2fjm0000gn/T/pip_build_mycomputername/lxml
Storing debug log for failure in /Users/mycomputername/.pip/pip.log

我该怎么办?

任何建议表示赞赏

2 个答案:

答案 0 :(得分:27)

I had that problem, and what I did is:

installed all xcode (2.8GB) from apple store.

to be sure that the installation is successfully finished: open terminal and typed

xcode-select -p

you should get something like this:

/Applications/Xcode.app/Contents/Developer

now you need to install command line tools. try to type gcc on the terminal, then there are two possibilities: either you get a window asking to install the tools and you have to click on install, or you will get an error message.

if you get an error message, then don't worry just try to install the tools using this command xcode-select --install

after that restart the mac and then re install lxml again like this :

pip install lxml

then try to run scrapy again

if you encounter any other error on any other library, easily just reinstall scrapy using easy_install and NOT using pip

答案 1 :(得分:0)

这可能是因为您在升级后没有重新安装命令行工具。

通常XCode应该升级到最新版本(4.4)(我相信当我更新到10.8时我还更新了一大堆其他应用程序,包括XCode)。更新后,您需要重新安装命令行工具。现在可以通过XCode中的设置来完成:

转到&#34;首选项 - &gt;下载&#34;并安装&#34;命令行工具&#34;。