macOS M1 又一个坑,在装wxpython时报错。
正常情况只需要 pip install wxpython?就能安装的,但是? M1? 芯片,macOs 11.52?下面编译不通过,报错。
(gxtimer) xulong@xulongdeMacBook-Pro GXTimer % pip install wxpython
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting wxpython
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b0/4d/80d65c37ee60a479d338d27a2895fb15bbba27a3e6bb5b6d72bb28246e99/wxPython-4.1.1.tar.gz (66.0 MB)
Requirement already satisfied: pillow in /Users/xulong/.pyenv/versions/3.9.6/envs/gxtimer/lib/python3.9/site-packages (from wxpython) (8.3.1)
Requirement already satisfied: six in /Users/xulong/.pyenv/versions/3.9.6/envs/gxtimer/lib/python3.9/site-packages (from wxpython) (1.16.0)
Requirement already satisfied: numpy in /Users/xulong/.pyenv/versions/3.9.6/envs/gxtimer/lib/python3.9/site-packages (from wxpython) (1.21.1)
Building wheels for collected packages: wxpython
Building wheel for wxpython (setup.py) ... error
。。。。
ff409983598c6914709fc3/ext/wxWidgets/src/common/imagtiff.cpp:37:14: fatal error: 'tiff.h' file not found
#include "tiff.h"
^~~~~~~~
提示 imagtiff.cpp 里引入的头文件找不到,这个应该是源代码文件地址可能不对引起的。只能去改源代码了。?下源代码的方式有几种。
1.安装时会提示下载地址(https://xxxxxxxx),直接按地址下载。
xulong@xulongdeMacBook-Pro test3.10 % pip install wxpython
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting wxpython
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b0/4d/80d65c37ee60a479d338d27a2895fb15bbba27a3e6bb5b6d72bb28246e99/wxPython-4.1.1.tar.gz (66.0 MB)
如果没有提示路径的话,那就是以前已经下载过,在pip的缓存里,所以不用下载,就不提示。可以清除缓存。
# pip cache dir 可以查看缓存目录。 然后用rm删掉。
(wxworkhelper) xulong@xulongdeMacBook-Pro test3.10 % pip cache dir
/Users/xulong/Library/Caches/pip
rm -rf /Users/xulong/Library/Caches/pip
2.利用pip download?下载
#利用pip download 下载源文件
(wxworkhelper) xulong@xulongdeMacBook-Pro test3.10 % pip download wxpython
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting wxpython
File was already downloaded /Users/xulong/dev/python/test3.10/wxPython-4.1.1.tar.gz
?将下载下来的源文件,解压出来,进入解压后目录,然后尝试编译?python setup.py build ,结果和上面用pip编译时出错一致。根据提示修改代码。?vim ext/wxWidgets/src/common/imagtiff.cpp
把文件改成对应的路径。
(ps:可以用find .? -name tiff.h? 找文件实际路径)
修改完了,再重新编译。 python setup.py build? ,编译成功。
这时候可以?用 python setup.py install?直接安装。?
为了保持和 pip list同步,我下面利用pip?编译成 wheel?包,再用pip install?安装
pip? wheel? wxPython-4.1.1? ? ?
#对源代码目录,用pip wheel 编译。
(wxworkhelper) xulong@xulongdeMacBook-Pro test3.10 % pip wheel wxPython-4.1.1/
Building wheels for collected packages: wxPython
Building wheel for wxPython (setup.py) ... \
|
done
Created wheel for wxPython: filename=wxPython-4.1.1-cp39-cp39-macosx_11_0_arm64.whl size=24233925 sha256=e5ebad8cfb420b78659ee972b5f2ecd5d8374078e804c459a49b146056bf6297
Stored in directory: /Users/xulong/Library/Caches/pip/wheels/4d/1a/d9/7d26e3665f6651d58cde82cfa964558c876f4c5960dbbba013
Successfully built wxPython
#编译成功后在当前目录产生了一个 .whl 文件, 后面用pip install 来安装即可。
#查看一下 确认是没有 wxpython模块。
(wxworkhelper) xulong@xulongdeMacBook-Pro test3.10 % pip list
Package Version
------------------------- ---------
altgraph 0.17.2
certifi 2021.5.30
charset-normalizer 2.0.4
cos-python-sdk-v5 1.9.8
crcmod 1.7
Cython 0.29.28
dicttoxml 1.7.4
idna 3.2
Jinja2 3.0.3
macholib 1.15.2
MarkupSafe 2.1.0
numpy 1.21.2
Pillow 8.3.1
pip 21.1.3
pycryptodome 3.10.1
pyinstaller 4.10
pyinstaller-hooks-contrib 2022.2
qrcode 7.3
requests 2.26.0
setuptools 56.0.0
six 1.16.0
urllib3 1.26.6
wheel 0.37.0
xlrd 2.0.1
wxworkhelper) xulong@xulongdeMacBook-Pro test3.10 % pip install wxPython-4.1.1-cp39-cp39-macosx_11_0_arm64.whl
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./wxPython-4.1.1-cp39-cp39-macosx_11_0_arm64.whl
Requirement already satisfied: pillow in /Users/xulong/.pyenv/versions/3.9.6/envs/wxworkhelper/lib/python3.9/site-packages (from wxPython==4.1.1) (8.3.1)
Requirement already satisfied: numpy in /Users/xulong/.pyenv/versions/3.9.6/envs/wxworkhelper/lib/python3.9/site-packages (from wxPython==4.1.1) (1.21.2)
Requirement already satisfied: six in /Users/xulong/.pyenv/versions/3.9.6/envs/wxworkhelper/lib/python3.9/site-packages (from wxPython==4.1.1) (1.16.0)
Installing collected packages: wxPython
Successfully installed wxPython-4.1.1
(wxworkhelper) xulong@xulongdeMacBook-Pro test3.10 % pip list
Package Version
------------------------- ---------
altgraph 0.17.2
certifi 2021.5.30
charset-normalizer 2.0.4
cos-python-sdk-v5 1.9.8
crcmod 1.7
Cython 0.29.28
dicttoxml 1.7.4
idna 3.2
Jinja2 3.0.3
macholib 1.15.2
MarkupSafe 2.1.0
numpy 1.21.2
Pillow 8.3.1
pip 21.1.3
pycryptodome 3.10.1
pyinstaller 4.10
pyinstaller-hooks-contrib 2022.2
qrcode 7.3
requests 2.26.0
setuptools 56.0.0
six 1.16.0
urllib3 1.26.6
wheel 0.37.0
wxPython 4.1.1 #*************有了
xlrd 2.0.1
完成,后面其它?虚拟环境要安装的话,只要用这个.whl文件就行了。
|