我已使用从官方 Python 站点下载的官方 OSX 包在 High Sierra 的默认位置安装了 Python 3.7。当我跑步时
which python3
我明白了路径
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
然后我在 R Studio 中运行以下几行
reticulate::use_python(python = '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3')
sys <- import("sys")
sys$version
看来我还是指的是默认安装2.7
[1] "2.7.10 (default, Oct 6 2017, 22:29:07) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]"
我尝试了许多其他路径,例如
/usr/local/bin/python3
/usr/local/bin
/Library/Frameworks/Python.framework/Versions/3.7/lib
/usr/bin/python
/Applications/Python 3.7
等等,但似乎都不起作用。 (仍然显示2.7.10)
显然,我已经尝试通过谷歌搜索解决方案,但不幸的是没有成功。
任何指导将不胜感激。
Update:我终于让它工作了:
- 按照 serv-inc 的建议重新启动 R 会话
-
运行以下命令:
library(reticulate)
reticulate::use_python(python = '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3', required = T)
sys <- import("sys")
sys$version
得到以下响应:
[1] "3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) \n[Clang 6.0 (clang-600.0.57)]"
如果我错误地指定了不正确的路径,例如/usr/bin/python
,我需要重新启动 R 会话,否则 reticulate 将继续引用现有的 Python 版本。
简而言之,该问题是由于初始调用时指定的不正确路径引起的reticulate::use_python
函数,并且使用正确路径的后续调用将不会生效,因为它需要“新”R 会话。
See https://github.com/rstudio/reticulate/issues/45 https://github.com/rstudio/reticulate/issues/45:
Do
library("reticulate")
use_python("/usr/bin/python", required = T)
在做其他事情之前。
也可以看看https://github.com/rstudio/reticulate/issues/227 https://github.com/rstudio/reticulate/issues/227:
reticulate 总是更喜欢包含 NumPy 的 Python 版本,而不是不包含 NumPy 的 Python 版本。 /usr/local/bin/python3 的版本有 NumPy 吗?
显然,我已经尝试过谷歌搜索解决方案
有时,仅谷歌搜索函数名称“reticulate::use_python”会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)