尝试在 macos 上使用 pip 安装任何东西,但不能
Posted
技术标签:
【中文标题】尝试在 macos 上使用 pip 安装任何东西,但不能【英文标题】:Trying to install anything with pip on macos and cannot 【发布时间】:2018-09-28 07:14:41 【问题描述】:我认为我的 mac os 系统有问题。我尝试使用 pip 在其上安装的所有内容我一遍又一遍地遇到相同的错误,我只粘贴了显示错误的行,以免使该线程过度拥挤:
Collecting murmurhash3
Using cached https://files.pythonhosted.org/packages/b5/f4/1f9c4851667a2541bd151b8d9efef707495816274fada365fa6a31085a32/murmurhash3-2.3.5.tar.gz
Building wheels for collected packages: murmurhash3
Running setup.py bdist_wheel for murmurhash3 ... error
Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-install-_4hr8w03/murmurhash3/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-wheel-k28wu_2e --python-tag cp37:
running bdist_wheel
running build
running build_ext
building 'mmh3' extension
creating build
creating build/temp.macosx-10.14-x86_64-3.7
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/include -I/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c mmh3module.cpp -o build/temp.macosx-10.14-x86_64-3.7/mmh3module.o
In file included from mmh3module.cpp:3:
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:14:2: error: "Something's broken. UCHAR_MAX should be defined in limits.h."
#error "Something's broken. UCHAR_MAX should be defined in limits.h."
^
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:18:2: error: "Python's source code assumes C's unsigned char is an 8-bit type."
#error "Python's source code assumes C's unsigned char is an 8-bit type."
^
mmh3module.cpp:99:5: error: use of undeclared identifier 'memcpy'; did you mean 'wmemcpy'?
memcpy(bytes, result, 16);
^~~~~~
wmemcpy
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/wchar.h:152:10: note: 'wmemcpy' declared here
wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
^
mmh3module.cpp:99:12: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [16]'
memcpy(bytes, result, 16);
^~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/wchar.h:152:38: note: passing argument to parameter here
wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
^
4 errors generated.
error: command 'clang' failed with exit status 1
----------------------------------------
Failed building wheel for murmurhash3
Running setup.py clean for murmurhash3
Failed to build murmurhash3
Installing collected packages: murmurhash3
Running setup.py install for murmurhash3 ... error
Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-install-_4hr8w03/murmurhash3/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-record-7a15nstl/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'mmh3' extension
creating build
creating build/temp.macosx-10.14-x86_64-3.7
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/include -I/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c mmh3module.cpp -o build/temp.macosx-10.14-x86_64-3.7/mmh3module.o
In file included from mmh3module.cpp:3:
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:14:2: error: "Something's broken. UCHAR_MAX should be defined in limits.h."
#error "Something's broken. UCHAR_MAX should be defined in limits.h."
^
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:18:2: error: "Python's source code assumes C's unsigned char is an 8-bit type."
#error "Python's source code assumes C's unsigned char is an 8-bit type."
^
mmh3module.cpp:99:5: error: use of undeclared identifier 'memcpy'; did you mean 'wmemcpy'?
memcpy(bytes, result, 16);
^~~~~~
wmemcpy
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/wchar.h:152:10: note: 'wmemcpy' declared here
wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
^
mmh3module.cpp:99:12: error: cannot initialize a parameter of type 'wchar_t *' with an lvalue of type 'char [16]'
memcpy(bytes, result, 16);
^~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/wchar.h:152:38: note: passing argument to parameter here
wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
^
4 errors generated.
error: command 'clang' failed with exit status 1
----------------------------------------
Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-install-_4hr8w03/murmurhash3/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-record-7a15nstl/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/15/_mc1281d6kn_z8my6cz6dj740000gq/T/pip-install-_4hr8w03/murmurhash3/
另一方面,当我尝试安装 lxml
或 requests
时,一切正常。对我搞砸的地方有什么想法吗?
【问题讨论】:
运行CPPFLAGS="" CFLAGS="" pip install murmurhash3
时是否仍然出现错误,只是为了排除可能的名称冲突?我的意思是,您传递了很多包含目录,而您唯一需要的应该是包含 python 头文件的目录。
【参考方案1】:
murmurhash3
库适用于 Python >3.2,起初您试图为 Python 2 编译它。它不起作用,因为该库具有 C 扩展名,并且 Python 2 和 3 互不兼容 API。
当然会更容易注意到,murmurhash3
是否会在其setup.py
中检查您的 Python 版本。
现在您正尝试将其安装到 Python 3,很明显您的编译器存在严重问题! C 标准要求UCHAR_MAX
由现有的每个 C 编译器在<limits.h>
中定义,并且在任何当前的个人计算架构上,UCHAR_MAX
应该被定义为255,包括 Mac。 Python.h 对此进行检查。您的 C 编译器既没有定义 UCHAR_MAX
,也没有在 limits.h
中将其设置为 255
,但它仍然成功地包含了 一些 limits.h
。你的 C 编译器完全是 b0rken
【讨论】:
我虽然可能是这种情况,但我尝试使用 pip3 安装它,并且发生了同样的愚蠢错误。/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:18:2: error: "Python's source code assumes C's unsigned char is an 8-bit type." #error "Python's source code assumes C's unsigned char is an 8-bit type."
您的 Python 3 设置可能是 b0rken,ofc。请将该安装日志复制到问题中
OK,这个错误证明你的环境完全是 b0rk3n。考虑到this code,我不知道 将如何在 Mac 上发生
我在发布这个问题之前已经重新安装了python,同样的问题。
@MihaiVinaga 是的,请尝试使用 #include <limits.h>
和 clang -E test.c
预处理 test.c
,它应该输出带有 UCHAR_MAX
定义的 <limits.h>
的内容... ?以上是关于尝试在 macos 上使用 pip 安装任何东西,但不能的主要内容,如果未能解决你的问题,请参考以下文章
在 MacOS 上安装 psycopg2 失败,错误消息不明确
无法在 MacOS 上通过 pip install 安装 psycopg2 包
在 macOS Mojave 10.14.5 上安装 python3-pip / flask [重复]
无法在 MacOS 10.12.4 上使用 pip 安装 mysql-python