我正在尝试在 RStudio 中导入 .py 文件,但收到错误消息:
Error in dir.exists(x) : file name conversion problem -- name too long?)
我已经尝试通过仅包含英文字母的路径运行它,但它不起作用。此外,
list.files()
的输出包括我尝试导入的文件。
library(reticulate)
library(tidyverse)
library(forcats)
setwd("C:/Users/Κατερίνα/Nextcloud/Multipic_Exp.1")
source_python("euler.py") --> Here I get the error message.
The traceback() output:
12: dir.exists(x)
11: utils::file_test("-d", version_dir)
10: read_python_versions_from_registry("HCU", key = "PythonCore")
9: rbind(read_python_versions_from_registry("HCU", key = "PythonCore"),
read_python_versions_from_registry("HLM", key = "PythonCore"),
windows_registry_anaconda_versions())
8: py_versions_windows()
7: python_conda_versions()
6: py_discover_config(required_module, use_environment)
5: (function() {
op <- options(reticulate.python.initializing = TRUE)
on.exit(options(op), add = TRUE)
py_discover_config(required_module, use_environment)
})()
4: initialize_python(required_module, use_environment)
3: ensure_python_initialized()
2: py_run_file(file, local = FALSE, convert = convert)
1: source_python("euler.py")
My sessionInfo():
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=Greek_Greece.1253 LC_CTYPE=Greek_Greece.1253 LC_MONETARY=Greek_Greece.1253
[4] LC_NUMERIC=C LC_TIME=Greek_Greece.1253
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_1.4.0 tidyr_1.1.3 tibble_3.1.2
[8] ggplot2_3.3.5 tidyverse_1.3.1 reticulate_1.26
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 cellranger_1.1.0 pillar_1.6.1 compiler_4.1.0 dbplyr_2.1.1 tools_4.1.0
[7] lubridate_1.8.0 jsonlite_1.8.4 lifecycle_1.0.3 gtable_0.3.0 lattice_0.20-44 pkgconfig_2.0.3
[13] png_0.1-7 rlang_1.0.6 reprex_2.0.1 Matrix_1.3-3 cli_3.4.1 DBI_1.1.1
[19] rstudioapi_0.13 haven_2.4.1 xml2_1.3.2 withr_2.4.2 httr_1.4.2 fs_1.5.2
[25] hms_1.1.0 generics_0.1.0 vctrs_0.5.1 rprojroot_2.0.2 grid_4.1.0 tidyselect_1.1.1
[31] here_1.0.1 glue_1.6.2 R6_2.5.1 fansi_0.5.0 readxl_1.3.1 modelr_0.1.8
[37] magrittr_2.0.3 scales_1.1.1 backports_1.2.1 ellipsis_0.3.2 rvest_1.0.2 assertthat_0.2.1
[43] colorspace_2.0-2 utf8_1.2.1 stringi_1.7.6 munsell_0.5.0 broom_0.7.8 crayon_1.4.1
这是一个老问题,但由于我刚才遇到了同样的问题,我会建议一个“硬件解决方法”。
根据其他讨论,大多数人的问题在于文件路径包含未在英语中使用的字母。
setwd("C:/Users/Κατερίνα/Nextcloud/Multipic_Exp.1")
在私人计算机上,人们可以更改这些名称(将 Κατερίνα 更改为 Katerina),但您可能不想这样做。另外,如果您在工作/学校等使用计算机,则可能无法更改目录名称。
将文件放在外部硬盘驱动器(即记忆棒)上可能会绕过麻烦的目录名称。