我正在尝试从mac上的命令行连接一些pdf文件。
在线阅读后,我发现这里有一个python脚本:
/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py
将我的python重置为系统的2.7 python(sudo port select --set python python27
)后,在尝试运行上述脚本时出现此错误:
Traceback (most recent call last):
File "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py", line 23, in <module>
from CoreFoundation import *
ImportError: No module named CoreFoundation
显然python无法导入名为CoreFoundation
的东西。看,我在文件系统的这个地方找到了CoreFoundation.py
:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/Carbon/CoreFoundation.py
事实上,检查sys.path
变量似乎表明上述目录被忽略了:
$ python
>>> import.sys
>>> sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages']
(原谅长期不间断的一条线。重点是,
'/选择/本地/库/框架/ Python.framework /版本/ 2.7 / LIB / python2.7 /高原-MAC / LIB-scriptpackages'
在sys.path
中找到,但是前面提到的
'/选择/本地/库/框架/ Python.framework /版本/ 2.7 / LIB / python2.7 /高原-MAC /炭'
不是。)所以我尝试手动添加到PYTHONPATH(以前是空的):
PYTHONPATH = “/选择/本地/库/框架/ Python.framework /版本/ 2.7 / LIB / python2.7 /高原-MAC /碳”
...但即使这样做,我也会遇到同样的ImportError: No module named CoreFoundation
错误。
我该怎么办?