Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Python executable to Ananconda #812

Closed
rouseguy opened this issue Sep 21, 2016 · 9 comments
Closed

Changing Python executable to Ananconda #812

rouseguy opened this issue Sep 21, 2016 · 9 comments
Assignees

Comments

@rouseguy
Copy link

I use Anaconda as my Python distribution.

How do I set the notebook so that it picks the Anaconda's Python and not the system default ?

@rouseguy
Copy link
Author

Figured this out. Need to use engine.path

```{python, engine.path="/anaconda/bin/python"}
import pandas as pd
print(pd.__version__)
data = pd.read_csv("~/Documents/data/train.csv")
print(train.head())

@MGallow
Copy link

MGallow commented Oct 7, 2016

This is a minor issue but is there a way to set Rstudio to default to the correct engine.path?

@kevinushey
Copy link
Contributor

Good question -- I think this could be accomplished with a knitr hook, e.g. in a setup chunk (pseudocode):

```{r setup}
knit_hooks$set(engine = function(before, options, envir) {
    # detect python, set engine.path
})
```

@yihui, does this sound like a solution?

@yihui
Copy link
Member

yihui commented Oct 8, 2016

@kevinushey It is a solution, but perhaps it feels a little weird. I just added a more straightforward approach to knitr, and you can install the development version via

devtools::install_github('yihui/knitr')

Then you can set up the path of python in a code chunk like this:

```{setup, include=FALSE}
knitr::opts_chunk$set(engine.path = list(python = '/anaconda/bin/python'))
```

And the rest of python code chunks will use /anaconda/bin/python.

@kevinushey
Copy link
Contributor

@yihui that's awesome, thanks!

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Mar 11, 2017
Upstream changes:

CHANGES IN knitr VERSION 1.15.1

@yihui yihui released this on 23 Nov 2016 · 49 commits to master since this release
NEW FEATURES

    added a new hook function hook_pngquant() that can call pngquant to optimize PNG images (thanks, @slowkow, #1320)

BUG FIXES

    not really a knitr bug, but knit_params() should be better at dealing with multibyte characters now due to the bug fix in the yaml package vubiostat/r-yaml#6

Downloads

    Source code (zip)
    Source code (tar.gz)

    v1.15
    b08a7bc

CHANGES IN knitr VERSION 1.15

@yihui yihui released this on 10 Nov 2016 · 63 commits to master since this release
NEW FEATURES

    NA values can be displayed using different characters (including empty strings) in kable(); you can set the option knitr.kable.NA, e.g. options(knitr.kable.NA = '') to hide NA values (#1283)
    added a fortran95 engine (thanks, @stefanedwards, #1282)
    added a block2 engine for R Markdown documents as an alternative to the block engine; it should be faster and supports arbitrary Pandoc's Markdown syntax, but it is essentially a hack; note when the output format is LaTeX/PDF, you have to define \let\BeginKnitrBlock\begin \let\EndKnitrBlock\end in the LaTeX preamble
    figure captions specified in the chunk option fig.cap are also applied to HTML widgets (thanks, @byzheng, rstudio/bookdown#118)
    when the chunk option fig.show = 'animate' and ffmpeg.format = 'gif', a GIF animation of the plots in the chunk will be generated for HTML output (https://twitter.com/thomasp85/status/785800003436421120)
    added a width argument to write_bib() so long lines in bib entries can be wrapped
    the inline syntax r#code is also supported besides r code; this can make sure the inline expression is not split when the line is wrapped (thanks, Dave Jarvis)
    provided a global R option knitr.use.cwd so users can choose to evaluate the R code chunks in the current working directory after setting options(knitr.use.cwd = TRUE); the default is to evaluate code in the directory of the input document, unless the knitr option opts_knit$set(root.dir = ...) has been set
    if options(knitr.digits.signif = TRUE), numbers from inline expressions will be formatted using getOption('digits') as the number of significant digits, otherwise (the default behavior) getOption('digits') is treated as the number of decimal places (thanks, @numatt, #1053)
    the chunk option engine.path can also be a list of paths to the engine executables now, e.g., you can set knitr::opts_chunk$set(engine.path = list(python = '/anaconda/bin/python', perl = '/usr/local/bin/perl')), then when a python code chunk is executed, /anaconda/bin/python will be called instead of the system default (rstudio/rmarkdown#812)
    introduced a mechanism to protect text output in the sense that it will not be touched by Pandoc during the conversion from R Markdown to another format; this is primarily for package developers to extend R Markdown; see ?raw_output for details (which also shows new functions extract_raw_output() and restore_raw_output())

MAJOR CHANGES

    the minimal version of R required for knitr is 3.1.0 now (#1269)
    the formatR package is an optional package since the default chunk option tidy = FALSE has been there for a long time; if you use tidy = TRUE, you need to install formatR separately if it is not installed
    :set +m is no longer automatically added to haskell code chunks (#1274)

MINOR CHANGES

    the package option opts_knit$get('stop_on_error') has been removed
    the confusing warning message about knitr::knit2html() when buiding package vignettes using the knitr::rmarkdown engine without pandoc/pandoc-citeproc has been removed (#1286)
    the default value of the quiet argument of plot_crop() was changed from !opts_knit$get('progress') to TRUE, i.e., by default the messages from cropping images are suppressed

BUG FIXES

    the chunk option cache.vars did not really behave like what was documented (thanks, @simonKTH, #1280)
    asis_output() should not be merged with normal character output when results='hold' (thanks, @kevinushey, #1310)

Downloads

    Source code (zip)
    Source code (tar.gz)

    v1.14
    b34be0d

CHANGES IN knitr VERSION 1.14

@yihui yihui released this on 12 Aug 2016 · 845 commits to master since this release
NEW FEATURES

    improved caching for Rcpp code chunks: the shared library built from the C++ code will be preserved on disk and reloaded the next time if caching is enabled (chunk option cache = TRUE), so that the exported R functions are still usable in later R code chunks; note this feature requires Rcpp >= 0.12.5.6 (thanks, @jjallaire, #1239)
    added a helper function all_rcpp_labels(), which is simply all_labels(engine == 'Rcpp') and can be used to extract all chunk lables of Rcpp chunks
    added a new engine named sql that uses the DBI package to execute SQL queries, and optionally assign the result to a variable in the knitr session; see http://rmarkdown.rstudio.com/authoring_knitr_engines.html for details (#1241)
    fig.keep now accepts numeric values to index low-level plots to keep (#1265)

BUG FIXES

    fixed #1211: pandoc('foo.md') generates foo_utf8.html instead of foo.html by default
    fixed #1236: include = FALSE for code chunks inside blockquotes did not work (should return > instead of a blank line) (thanks, @fmichonneau)
    fixed #1217: define the command \hlipl for syntax highlighting for Rnw documents (thanks, @conjugateprior)
    fixed #1215: restoring par() settings might fail when the plot window is partitioned, e.g. par(mfrow = c(1, 2)) (thanks, @jrwishart @jmichaelgilbert)
    fixed #1250: in the quiet mode, knit() should not emit the message "processing file ..." when processing child documents (thanks, @KZARCA)

MAJOR CHANGES

    knitr will no longer generate screenshots automatically for HTML widgets if the webshot package or PhantomJS is not installed

MINOR CHANGES

    if dev = 'cairo_pdf', the cairo_pdf device will be used to record plots (previously the pdf device was used) (#1235)
    LaTeX short captions now go up to the first ., : or ; character followed by a space or newline (thanks, @knokknok, #1249)
@MichaelChirico
Copy link
Contributor

for the record this should be documented here: http://rmarkdown.rstudio.com/authoring_knitr_engines.html

@aedobbyn
Copy link

aedobbyn commented Feb 19, 2018

Unfortunately, neither setting my opts_chunk like this nor editing my .Rprofile to add Sys.setenv(PATH = paste("<path_to_python3>", Sys.getenv("PATH"), sep=":")) has set the default python correctly. I have no trouble setting an individual chunk to run python3 by setting the engine.path for that chunk, but setting all chunks to default to python3 hasn't worked; it still defaults to python2 (the Apple default in /usr/bin/python). I'm on version 1.1.423 of RStudio for Mac and R version 3.3.3. @yihui I'd love to hear any suggestions about what I might be doing wrong.

Edit
The inline chunk does say the version is Python 2.7.10 but when it's knit it says the same chunk is Python 3.6.3 😕

@mjbeyeler
Copy link

I'm having the same issue. I can't get RStudio to recognize my Anaconda 2 python.

What WOULD work, is adding Anaconda to %PATH%, but I don't want to do that because that causes all sorts of other troubles in Windows.

@rich-iannone rich-iannone self-assigned this May 16, 2018
@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants