You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac环境下无法修改Astropy缓存路径的技术求助

解决Astropy缓存目录无法修改的问题

你使用的astropy.config.set_temp_cache()是用于创建临时缓存目录的接口,它仅在当前Python会话内临时生效(即使设置delete=False也不会覆盖系统默认的持久化缓存路径),这就是为什么get_cache_dir()仍返回默认路径的原因。

要修改Astropy的持久化缓存目录,可通过以下几种方法实现:

方法1:代码内全局设置

需在导入Astropy子模块(如astropy.io、astropy.table等)之前执行配置修改:

from astropy import config as conf

# 直接指定持久化缓存目录
conf.conf.cache_dir = '/Users/josephprendergast/Documents/Temp/'

# 验证设置是否生效
print(conf.get_cache_dir())

方法2:通过环境变量设置

在Mac终端中配置环境变量,可让所有Astropy会话共享该缓存目录:

# 当前终端会话临时生效
export ASTROPY_CACHE_DIR="/Users/josephprendergast/Documents/Temp/"

# 永久生效(根据你的shell类型修改配置文件,zsh用~/.zshrc,bash用~/.bash_profile)
echo 'export ASTROPY_CACHE_DIR="/Users/josephprendergast/Documents/Temp/"' >> ~/.zshrc
source ~/.zshrc

方法3:修改Astropy配置文件

找到用户配置目录~/.astropy/config/,创建或编辑astropy.cfg文件,添加以下内容:

[cache]
cache_dir = /Users/josephprendergast/Documents/Temp/

保存后重启Python会话即可生效。


内容的提问来源于stack exchange,提问作者JoeP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 17:54:52