我在为python安装 astropy 时遇到问题。 当我在终端输入'pip install astropy'时,我收到此消息:
Collecting astropy
Using cached astropy-1.0.4.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/var/folders/8g/ggchkyrx1xv7jk9df887m1cr0000gq/T/pip-build-63p1fldn/astropy/setup.py", line 49, in <module>
adjust_compiler(NAME)
File "/private/var/folders/8g/ggchkyrx1xv7jk9df887m1cr0000gq/T/pip-build-63p1fldn/astropy/.eggs/astropy_helpers-1.0.3-py3.4.egg/astropy_helpers/setup_helpers.py", line 197, in adjust_compiler
if re.match(broken, version):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/re.py", line 160, in match
return _compile(pattern, flags).match(string)
TypeError: can't use a bytes pattern on a string-like object
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/8g/ggchkyrx1xv7jk9df887m1cr0000gq/T/pip-build-63p1fldn/astropy
任何人都知道为什么会这样?
答案 0 :(得分:2)
你是OS X吗?似乎天文的setup.py
试图避免在您的系统上使用 llvm-gcc 编译器。在astropy的一个辅助方法中可能存在一个错误,但是您可以通过明确地将 clang 默认编译器放在此代码路径中来避免它:
$ export CC=clang
$ export CXX=clang++
$ export FFLAGS=-ff2c
然后重新运行pip install astropy
编辑:由于上述内容不适合您,请尝试手动安装。
安装Xcode命令行工具,以确保系统上安装了clang
:http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/
xcode-select --install
将配置CC
的环境变量clang
设置为默认编译器
export CC=clang
下载astropy tarball
curl -O https://pypi.python.org/packages/source/a/astropy/astropy-1.0.4.tar.gz
解压缩astropy tarball
tar zxvf astropy-1.0.4.tar.gz
将目录更改为astropy-1.0.4
文件夹
cd astropy-1.0.4
尝试手动修补导致安装失败的错误。首先在文本编辑器中打开setup_helpers.py
vim astropy_helpers/astropy_helpers/setup_helpers.py
修改第110行。 删除“ b ”。
即。变化:
(b'i686-apple-darwin[0-9]*-llvm-gcc-4.2', 'clang')
要:
('i686-apple-darwin[0-9]*-llvm-gcc-4.2', 'clang')
从astropy-1.0.4/
文件夹执行手动安装:
sudo python setup.py install