3

I apologise first as I am very new to much of this.

I am working in Markdown and I want to use the python package tweepy. Now this requires a more updated version of Python than my current one:

import sys
print(sys.version)

which gives me

2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]

Because I get

ImportError: No module named tweepy

when I try to import it.

So I have downloaded Python version 2.7.14 to my laptop, and I find it as a folder in Applications ( I am on a Mac using OS X 10.11.6 ).

This has updated the Python used when I open terminal, but the code chunks still use the old version. I am unsure of how to save this version of Python to a different location. I feel like what I need to do is change the engine.path parameter in the code chunk, but I am not sure how I move this version of Python and refer to it in the engine.path.

Any help would be greatly appreciated!!

Best wishes

B

1 Answers1

0

This is a common problem when using knitr and RMarkdown. You need to set the engine.path variable in your chunk. If you are using Anaconda, it might look like this...

```{python, engine.path="~/anaconda3/bin/python"}
your code here...
```

If you open python in your terminal and run...

import sys
print(sys.executable)

It should point you to the location of the python executable you should pass as an argument to engine.path in RMarkdown/knitr.

Chris Conlan
  • 2,774
  • 1
  • 19
  • 23