Mac下查找python的安装位置以及第三方库
因为有时候会写一个工具放在lib下,对于windows是很好找python安装包的地址以及lib 和 site-packages
但是对于mac来说却是不太容易,现提供方法如下:
亲测可用
1.首先找site-packages
import sys print(sys.path)
/usr/local/bin/python3.7 /Users/tuyoo/Documents/pytext/test02/other_file/a_011.py ['/Users/tuyoo/Documents/pytext/test02/other_file', '/Users/tuyoo/Documents/pytext/test02', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
/usr/local/bin/python3.7 /Users/tuyoo/Documents/pytext/test02/other_file/a_011.py ['/Users/tuyoo/Documents/pytext/test02/other_file', '/Users/tuyoo/Documents/pytext/test02', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages'] #site-packages 所在
想进入到该路径下可根据找lib方法找这个文件
2.找lib
我们从上一条数据里摘抄出和lib相关的
'/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', ' /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
可以查一下路径下的文件:(建议拿windows路径下的文件做个对比找到存储位置,比如win下 py下lib下文件有哪些)
方法1:用终端进入到指定路径下,查看文件
方法2:使用访达 快捷键:command + Shift + G
(1)打开访达 (2)操作快捷键输入路径 (3)前往 (4)查看文件
经过查找,发现此路径下文件与Windows下py自导lib文件一致
备注:把写好的工具拽到lib下,放在lib以后可以通过:import 模块”导入不报错 就是成功