“Error in sys$stdout$flush() : attempt to apply non-function” - python

I am trying to use the "reticulate" package in R to run python code in my R script. I have tried to run very simple commands just to see if it is working, and I get the following error every time.
“Error in sys$stdout$flush() : attempt to apply non-function”
I have uninstalled and installed both R and Python to the most up to date versions. I'm not sure what else to do, it seems the reticulate packages definitely works for others and only a few have had this issue with no clear answers as to why.
Please help!
library(reticulate)
py_run_string("import numpy as np")
py_run_string("my_python_array = np.array([2,4,6,8])")
print(my_python_array)
py_run_string("print(my_python_array)")

This may be the same issue as reported here: https://github.com/rstudio/reticulate/issues/584
In R, you can download the possible fix from the master branch at github:
devtools::install_github("rstudio/reticulate")

Related

Error occurring when I execute commands in Python

I have just gotten a new computer and I had to reinstall anaconda (python version 3.7.3) and I am getting the following error when I execute commands. There does not seem to be any specific commands that it happens with, I can't correlate it with any one module.
C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\ipkernel.py:448: DeprecationWarning: `input_splitter` is deprecated since IPython 7.0, prefer `input_transformer_manager`.
status, indent_spaces = self.shell.input_splitter.check_complete(code)
After searching online, it seems like one of my dependencies might be causing this. At first I thought it was geopandas or numpy but i don't think it is. I am relatively new to python so if anyone has any advice on how to solve this, that would be great.
thanks

code execution cannot complete as python38.dll not found

i have no idea what i have done to cause this but when running C:>python .... (image 1) i get this error (image two)
i've tried repairing the install and running a full scan for any viruses and it's all going normal but then i still get this error
image 1:
image 2:
i'd just like to thank anyone who may be able to help in advance too!
When you type py command Python 3.9.2 is launched. However, when you type python the error message shows that python38.dll wasn't found which is a different version. It seems like you had different versions of Python and maybe some uninstallation process went wrong.
Are you able to check what do you have on PATH? The issue might be there. You can also try to uninstall all Python-related apps and install a fresh Python 3.9

Why am I unable to run the .login() attribute for robin_stocks?

I'm trying to import data from Robinhood through robin_stocks. I was able to import the package, but when I try to use the .login() attribute, it returns this error message in the Jupyter Notebook: error
module 'robin_stocks' has no attribute 'login'
I'm certain that robin_stocks does, indeed have the attribute that Python is telling me doesn't exist. Where did I go wrong here?
I'm relatively new to programming, but usually I can find an answer to my questions pretty quickly on StackOverflow or any other resource. I can't seem to figure this one out, though.
Any help would be greatly appreciated. Thank you!
I had the same error when upgrading from 1.7.x to 2.0.3
I was able to solve this by changing the import from:
import robin_stocks as rs
To:
import robin_stocks.robinhood as rs
Check the version of the package that you are using. I actually had the same issue when I migrated to a new laptop and installed packages again. I turned out that a newer robin-stocks python package got installed and resulted in an attribute error for my previously functioning code. When I reverted back to the older version of the package (1.5.5) my code worked like a charm.
Bro, we can't guess what you has typed in your code, please link it to us.
But if you have some issues with basic method of module, i think some thing gone wrong with import

Python Reticulate not working in Rstudio Cloud

I am a big fan of Rstudio Cloud and would like to inter-grate R and Python by using the package Reticulate.
It looks like Rstudio Cloud is using python 2.7 (no problems with that). When I try to write Python Code in an R markdown document, nothing gets run.
---
title: "reticulate"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(reticulate)
py_config()
```
```{python}
import pandas
x = 4
```
Python code does not get run.
I am also finding that if I want to install python packages in an R script using reticulate. I have to create a virtual environment. What is the reason behind that?
library(reticulate)
virtualenv_create("r-reticulate")
virtualenv_install("r-reticulate", "scipy")
virtualenv_install("r-reticulate", "pandas")
If I use conda_install, I get an error message.
conda_create("r-reticulate")
Error: Unable to find conda binary. Is Anaconda installed?
conda_install("r-reticulate", "scipy")
Error: Unable to find conda binary. Is Anaconda installed?
The goal is to have python working in Rstudio cloud on R markdown. I can not install packages and execute code.
I just succeeded in getting Conda installed in Rstudio cloud after receiving the same error message as you1, so thought I'd share how I got this working.
I created two scripts:
to install miniconda (i think that's the step you're missing, and why Conda didn't work for you) and then restartSession for this to be accessible
to seperately store the commands for setting up Conda, with the running of this script passed as a command to the call to restartSession (because otherwise the commands are triggered before R has restarted, and they fail; sys.sleep() didn't seem to work, but this method did)
setup.R
setwd("/cloud/project") # to ensure students get required resources
install.packages("rstudioapi") # to restart R session w/ installations
install.packages("reticulate") # for python
reticulate::install_miniconda("miniconda") # for python
# Restart again to make sure all system things are loaded
# and then create a new Conda environment
rstudioapi::restartSession(command="source('nested_reticulate_setup.R')")
nested_reticulate_setup.R
reticulate::conda_create("r-reticulate")
reticulate::conda_install("r-reticulate", "scipy")
Sys.setenv(RETICULATE_PYTHON="/cloud/project/miniconda/envs/r-reticulate/bin/python")
reticulate::use_condaenv("r-reticulate")
osmnx <- reticulate::import("scipy")
Then if you make a call to scipy, eg scicpy$`__version__` , I believe it should work for you without that error you observed.
I couldn't find a solution to this issue elsewhere, so thought it worth responding to this old post in case it helps somebody some day. I am sure there are other ways of approaching this.
1 Perhaps for a different reason; i'll explain later in the post...

Error in loadNamespace(name) Cairo

It's my first time using R in jupyter. I've installed everything like jupyter, python, R and lRkernel. I can use just typing or calculation in jupyter but whenever I want to use a graph library like plot or ggplot2 it shows
Error in loadNamespace(name): there is no package called 'Cairo'
Traceback: plot without title
Someone please guide me about how to handle this issue.
I had the precise same issue and fixed it by installing Cairo package:
install.packages("Cairo")`
library(Cairo)
Thanks to my collegue Bartek for providing this solution

Categories