我使用从官方 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)
显然,我曾尝试使用谷歌搜索解决方案,但不幸的是无济于事。 任何指导将不胜感激。
更新: 我终于让它工作了:
- 按照 serv-inc 的建议重新启动 R session
运行以下命令:
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 session ,否则 reticulate 将继续引用现有的 Python 版本。
简而言之,问题是由于初始调用reticulate::use_python
时指定的路径不正确造成的。函数,并且使用正确路径的后续调用将不会生效,因为它需要一个“新的”R session 。
最佳答案
参见 https://github.com/rstudio/reticulate/issues/45 :
Do
library("reticulate") use_python("/usr/bin/python", required = T)
Before anything else.
另见 https://github.com/rstudio/reticulate/issues/227 :
reticulate will always prefer a version of Python that includes NumPy to one that doesn't. Does the version at /usr/local/bin/python3 have NumPy?
Obviously, I have tried googling for the solution
有时,仅通过谷歌搜索函数名称“reticulate::use_python”会有帮助。
关于python - 如何在 OSX High Sierra 中正确设置网状包的 Python 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52462780/