提问人:zedoshi 提问时间:8/2/2023 最后编辑:zedoshi 更新时间:8/7/2023 访问量:101
尝试运行 rpy2 会导致错误0x7e,并且找不到“sh”命令
Trying to run rpy2 results in error 0x7e, and 'sh' command not found
问:
我已经安装了 R,然后在 cmd 中使用“pip install rpy2”安装了 rpy2。在运行在线找到的随机简单 rpy2 代码示例后,我收到此错误消息(此错误消息实际上是由 cmd 中的“python -m rpy2.situation”发出的,因为 vscode 中的错误消息是信息较少的较小版本):
C:\Users\richardg>python -m rpy2.situation
rpy2 version:
3.5.13
Python version:
3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)]
Looking for R's HOME:
Environment variable R_HOME: C:\Program Files\R\R-4.3.1
InstallPath in the registry: C:\Program Files\R\R-4.3.1
Environment variable R_USER: C:\Program Files\R\r_user_directory_path
Environment variable R_LIBS_USER: C:\Program Files\R\r_libs_user
R version:
In the PATH: R version 4.3.1 (2023-06-16 ucrt) -- "Beagle Scouts"
Loading R library from rpy2: cannot load library 'C:\Program Files\R\R-4.3.1\bin\x64\R.dll': error 0x7e
Additional directories to load R packages from:
None
C extension compilation:
'sh' is not recognized as an internal or external command,
operable program or batch file.
Warning: Unable to get R compilation flags.
Directory for the R shared library:
'sh' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\richardg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\rpy2\situation.py", line 496, in <module>
for row in iter_info():
File "C:\Users\richardg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\rpy2\situation.py", line 454, in iter_info
yield get_r_libnn(r_home)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\richardg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\rpy2\situation.py", line 263, in get_r_libnn
return _get_r_cmd_config(r_home, 'LIBnn',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\richardg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\rpy2\situation.py", line 246, in _get_r_cmd_config
output = subprocess.check_output(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('C:\\Program Files\\R\\R-4.3.1\\bin\\x64\\R', 'CMD', 'config', 'LIBnn')' returned non-zero exit status 1.
我从解决此问题的徒劳尝试中收集到的是,这里有两件事很重要:
- 加载 R 0x7e出错.dll 从 rpy2 加载 R 库:无法加载库“C:\Program Files\R\R-4.3.1\bin\x64\R.dll”:错误 0x7e
- “sh”不被识别为内部或外部命令, 可操作的程序或批处理文件。
我尝试过什么 1. -
- 检查 R.dll 是否真的存在(它是)
- 尝试运行并使用 R 本身(它有效)
关于 2.-
- 检查未识别的“sh”是本地 RPY2 问题还是全局问题
- 这是 rpy2 问题,运行了这个建议并起作用:
import ctypes
def main():
print("Hello from Python!")
if __name__ == "__main__":
main()
答:
0赞
zedoshi
8/7/2023
#1
OSError:无法加载库“gobject-2.0”:错误0x7e
从 Python 3.8 开始,现在可以更安全地解析 Windows 上加载了 ctypes 的扩展模块和 DLL 的 DLL 依赖项。仅搜索系统路径、包含 DLL 或 PYD 文件的目录以及使用 add_dll_directory() 添加的目录以查找加载时依赖项。具体而言,不再使用 PATH 和当前工作目录,对这些目录的修改将不再对正常的 DLL 解析产生任何影响。 如果您遵循了官方文档中的安装指南,则以下示例有效。
解决0x7e错误似乎使 rpy2 正常运行,我不需要费心尝试修复“sh”错误
“sh”不被识别为内部或外部命令、可操作程序或批处理文件。
评论