hid*_*ush 10 python r reticulate
我正在尝试在 R 中使用 python 包,但我不断收到相同的错误:
ImportError: cannot import name 'read_csv' from 'pandas' (unknown location)
我也不能使用“py_install”:
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- python=3.1
Current channels:
- https://conda.anaconda.org/conda-forge/win-64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
Error: one or more Python packages failed to install [error code 1]
Run Code Online (Sandbox Code Playgroud)
我尝试指定包所在的文件夹,但它不起作用。希望大家能帮忙。
我的代码:
library(reticulate)
use_condaenv("C:/Users/Bruger/AppData/Local/r-miniconda/envs/r-reticulate")
import("pandas")
py = py_run_string
py("import pandas as pd")
py("from pandas import read_csv")
Run Code Online (Sandbox Code Playgroud)
Dan*_*zes 12
这个问题与R无关,也许你的代码没有任何问题。以下 SO 问题也出现了相同类型的问题:
如果您需要 python 3.10 或更高版本,则必须有 conda 4.11 或更高版本。安装所需的 conda 版本,或切换到基础环境并使用更新 condaconda update conda。就像是:
conda activate base
conda update conda
conda create --name r-reticulate python=3.10 pandas numpy scipy matplotlib scikit-learn
conda activate r-reticulate
Run Code Online (Sandbox Code Playgroud)
您可能需要向您的 conda 添加非默认通道,因为我正在UnsatisfiableError使用它。通过使用 conda-forge 通道,例如,我没有收到错误(但这可能会安装比通常更新的软件包):
conda create --name r-reticulate -c conda-forge python=3.10 pandas numpy scipy matplotlib scikit-learn
Run Code Online (Sandbox Code Playgroud)
使用 python 3.9 或更早版本从基础安装另一个环境
conda activate base
conda create --name r-reticulate python=3.9 pandas numpy scipy matplotlib sklearn
conda activate r-reticulate
Run Code Online (Sandbox Code Playgroud)
创建并激活 python 3.10 环境后,您基本上无法安装任何东西。您甚至无法安装 conda-build:
conda install conda-build -y
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
ResolvePackageNotFound:
- python=3.1
Run Code Online (Sandbox Code Playgroud)
Conda 4.10 包含 python 3.9 , conda 4.11 包含 python 3.10,因此您的基础环境应该与其中的 python 版本兼容。
如果您认为您的问题重复,请检查如何改进它。
这个答案与meta一致。我相信这是一个应该接受完全相同答案的例子,但我也定制了问题的答案。
这对我有用
library(reticulate)
x = import('pandas')
x$read_excel()
Run Code Online (Sandbox Code Playgroud)
您可以通过这种方式安装包
py_install("pandas")
Run Code Online (Sandbox Code Playgroud)