Conda reports PackagesNotFoundError: python=3.1 for reticulate environment
Asked Answered
F

2

10

I'm trying to use python packages in R, but I keep getting the same error:

ImportError: cannot import name 'read_csv' from 'pandas' (unknown location)

I cant use "py_install" neither:

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]

I have tried to specify my folder in which the packages are in, but it doesn't work. Hope you guys can help.

My code:

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")

enter image description here

Facilitate answered 13/10, 2021 at 8:3 Comment(1)
I'm not sure that I understand your comment, can you try to explain it again. The image just show the path to the directory.Facilitate
C
13

Conda 4.10 is incompatible with python 3.10.

The issue is not related to R, and maybe there is nothing wrong with your code. The same type of problem occurred at the following SO issues:

Solutions

If you need python 3.10+

If you need python 3.10 or newer, you must have conda 4.11 or newer. Install the desired conda version, or switch to the base environment and update conda using conda update conda. Something like:

conda activate base
conda update conda
conda create --name r-reticulate python=3.10 pandas numpy scipy matplotlib scikit-learn
conda activate r-reticulate

You may need to add non-default channels to your conda, as I get an UnsatisfiableError using it. By using the conda-forge channel e.g., I got no error (but this may install newer than usual packages):

conda create --name r-reticulate -c conda-forge python=3.10 pandas numpy scipy matplotlib scikit-learn

If you want to keep the old conda

Install another environment from base with python 3.9 or older like

conda activate base
conda create --name r-reticulate python=3.9 pandas numpy scipy matplotlib sklearn
conda activate r-reticulate

Other symptoms

You basically cannot install anything after creating and activating your python 3.10 environment. You cannot even install 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

Conda 4.10 contains python 3.9 and conda 4.11 contains python 3.10, so your base environment should be compatible with the python version therein.

duplicate?

If you believe that your question is a duplicate, please check how you can improve it.

This answer is in agreement with meta. I believe this is an example where exactly the same answer should be accepted, but I also customized the answer to the question.

Camp answered 10/12, 2021 at 12:13 Comment(2)
Please do not tell people with duplicate questions to delete them. Often a question is a duplicate by the nature of the terminology that different users are comfortable with. Having multiple questions that phrase the same question differently is a good thing. The community can then close vote duplicates to consolidate towards a canonical version of a question and possible answers.Ecclesiology
@Ecclesiology My answers to duplicated questions were removed because they were duplicates, however, I felt that in this case, duplicate answers are appropriate, or if they are not, then the questions too should be removed. I now customized the answers, so they are not duplicates, and as requested, I modified the instruction to improve the duplicated questions. I welcome any further suggestion on improving my answers, thanks :)Camp
S
0

This works for me

library(reticulate)
x = import('pandas')
x$read_excel()

You can install the package in this way

py_install("pandas")
Spearmint answered 13/10, 2021 at 8:38 Comment(8)
Gives me: AttributeError: module 'pandas' has no attribute 'read_excel'Facilitate
What is the version of your package? My version is 1.2 The error means that the package is not running. Did you install the pandas library in python?Spearmint
That I can't check in R, it also gives me an error... Another thing that is weird is, that I both have this path "C:\Users\Bruger\AppData\Local\r-miniconda\envs\r-reticulate" but also this "C:\Users\Bruger\miniconda3\envs" - The last one seems empty. I have uses miniconda prompt and installed with "conda_install pandas"Facilitate
You can install the package directly from R by the py_install functionSpearmint
Check new edit in postFacilitate
The use_python() function enables you to specify an alternate version fo pythonSpearmint
I have tried to do this use_python(3.9) which doens't change anything :(Facilitate
I suggest you to check this: rstudio.github.io/reticulate/index.htmlSpearmint

© 2022 - 2024 — McMap. All rights reserved.