如何在 OSX High Sierra 中正确设置网状包的 Python 路径?
How to properly set the Python path for the reticulate package in OSX High Sierra?
我使用从官方 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
等,但 none 似乎有效。 (它仍然显示 2.7.10)
显然,我已经尝试使用谷歌搜索解决方案,但不幸的是无济于事。
任何指导将不胜感激。
更新:
我终于让它工作了:
- 按照 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
函数时指定的路径不正确,后续调用正确的路径不会生效,因为需要'fresh' R 会话。
参见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 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
等,但 none 似乎有效。 (它仍然显示 2.7.10)
显然,我已经尝试使用谷歌搜索解决方案,但不幸的是无济于事。 任何指导将不胜感激。
更新: 我终于让它工作了:
- 按照 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
函数时指定的路径不正确,后续调用正确的路径不会生效,因为需要'fresh' R 会话。
参见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" 会有帮助。