Unable to change Python path in reticulate - r

The first lines I run when launching my rstudio session are:
library(reticulate)
use_python("/usr/local/lib/python3.6/site-packages")
However, when I run py_config() it shows as still using the default python 2.7 installation.
This is an issue because I'm unable to import any modules that were installed for python3. Any idea why this isn't working? I followed documentation fairly closely.

I observed that neither the technique "use_python('path')" nor the tactic of Sys.setenv(RETICULATE_PYTHON = 'path') in .RProfile worked for me (of course I am sure it must have worked for others.)
In any case the line at terminal,
which -a python python3
did produce two paths to choose from (one for python2 and one for python3 installed on my mac), so then I was able to create a ".Renviron" file in my home directory with this single line in it:
RETICULATE_PYTHON="/usr/local/bin/python3"
After I restarted RStudio, library(reticulate) activates the desired python3, and repl_python() opens a python3 interactive window, etc. etc.

It worked for me:
Sys.setenv(RETICULATE_PYTHON = "/usr/bin/python3")
library(reticulate)
It seems important that you set RETICULATE_PYTHON before you first use reticulate.

use_python("path/to/python3") definitely does not work, although the Reticulate Python version configuration article says so. Don't believe it! :-)
I have tried to set the interpreter with the current Reticulate version (1.13), and the package gave me a very honest answer:
> library("reticulate")
> repl_python()
Python 2.7.15 (/usr/bin/python)
Reticulate 1.13 REPL -- A Python interpreter in R.
> use_python('/usr/bin/python3', require=T)
ERROR: The requested version of Python ('/usr/bin/python3') cannot be
used, as another version of Python ('/usr/bin/python') has already been
initialized. Please restart the R session if you need to attach
reticulate to a different version of Python.
Error in use_python("/usr/bin/python3", require = T) :
failed to initialize requested version of Python
Luckily, putting a .Renviron file containing the line RETICULATE_PYTHON="/path/to/python3" into the user's home directory does work:
> library("reticulate")
> py_config()
python: /usr/bin/python3
libpython: /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so
pythonhome: /usr:/usr
version: 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0]
numpy: [NOT FOUND]
NOTE: Python version was forced by RETICULATE_PYTHON
Finally, here comes the added value of my answer:
You can configure the Reticulate Python interpreter for all users by adding the RETICULATE_PYTHON line to the global Renviron file. It is usually found in the etc subdirectory of R's home directory. You can find out where R's home is by running the R.home() function in the R interpreter. In my case (Ubuntu 18.04.3 LTS) it was /usr/lib/R, so I edited /usr/lib/R/etc/Renviron. You obviously need admin rights to do this.

The only thing that work for me on Mac OSX, perform the following commands in the terminal:
touch $HOME/.Renviron
Then open it, I use vim, so my command is then the following:
vim $HOME/.Renviron
Add the following (for anaconda):
RETICULATE_PYTHON="/anaconda3/bin/python"
Otherwise, in the terminal type: which python3 and enter your output path
RETICULATE_PYTHON="your path from which python3"

It worked for me:
Sys.setenv(RETICULATE_PYTHON = "C:\ProgramData\Anaconda3")
library(reticulate)
repl_python()

Install numpy in the python environment you wish to use.
pip install numpy
I found that Reticulate refuses to use a version of python that does not have numpy installed.
I figured this out by running:
library("reticulate")
py_discover_config()
Reticulate skipped the first two version of python listed and used the third. I noticed it printed out the numpy version so it was probably looking for it as a requirement. It is not mentioned in the docs and should probably be added as a common problem.

For windows users, after creating a virtualenv python :
virtualenv python
this worked to use the virtualenv
Sys.setenv(RETICULATE_PYTHON = "python/Scripts/python.exe")
library(reticulate)
py_config()
EDIT:
This works for any path, e.g.
Sys.setenv(RETICULATE_PYTHON = "C:/Users/UserA/Anaconda3/envs/myEnv/python.exe")
To avoid having to do it each time, add the Sys.setenv line to RProfile:
file.edit(file.path("~", ".Rprofile"))
file.edit(".Rprofile")

You have to discover the path to your the .exe python file and then specify it in the .Renviron file.
The best is to create a conda environment to your project and then specify it as your reticulate path.
library(reticulate)
conda_create("environment name", packages = c("pandas", "matplotlib", "seaborn"), conda = "auto") # creates conda environment for your project
conda_python("environment name") # returns the .exe python path for your environment
Keep this path for the .Renviron file!!
To edit the .Renviron file:
library(usethis)
edit_r_environ()
Then, the .Renviron file will open. Paste the .exe path in it as follows:
RETICULATE_PYTHON="YOUR ENVIRONMENT PATH/python.exe"
Remember to paste it with / instead of "\".
Restart the R session and use the following command to check if everything is right:
library(reticulate)
py_config()
If everything is right, you should get something like:
python: YOUR ENVIRONMENT PATH/python.exe
libpython: YOUR ENVIRONMENT PATH/python39.dll
pythonhome: YOUR ENVIRONMENT PATH
version: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Architecture: 64bit
numpy: YOUR ENVIRONMENT PATH\lib\site-packages\numpy
numpy_version: 1.21.2
After this it should work :)

Posting this as an answer for visibility. None of the other methods worked for me. Fortunately you can select your interpreter from Tools→Global Options→Python.
It will ask you to restart R Studio. But when you do and use reticulate::py_config() it will give the correct version.

Related

Making system2 use a specific version of python

I have both python2 and python3 installed on my desktop. If I do
python -V in the terminal I get Python 3.6.0 :: Anaconda 4.3.0 (x86_64).
However if I use the system2 command from R
system2("python", args = "-V")
then it reports Python 2.7.10
If I specify the full path it I get the right version
system2("//anaconda/bin/python", args = "-V")
Python 3.6.0 :: Anaconda 4.3.0 (x86_64)
But I'd like system2 to just use python3 by default. Is there someway to change which version it uses? This is for Mac OSX
When running R from the R application or RStudio, system calls access a different environment than they do when you run R from terminal. Because of that, the PATH environment variable you have configured to run the correct version of a unix executable in a shell program is different than the one used in a system2()or system() call in an R session in either of these applications. To solve this, you need to set the path in your R environment.
In an interactive session, you can do this:
# Reproducing your problem (in the R application or RStudio)
system2("python", args="-V")
# Python 2.7.10
# set a new PATH in the environment accessed by R
# This is the line you can also add to your .Rprofile
Sys.setenv(PATH = paste(c("//anaconda/bin", Sys.getenv("PATH"),
collapse = .Platform$path.sep))
# For users other than the OP, you'll want to use the directory
# where your preferred installation of python is. For the OP that's
# //anaconda/bin
# Confirm
system2("python", args="-V")
# Python 3.6.0 :: Anaconda 4.3.0 (x86_64)
The system command python should now be found in the directory //anaconda/bin, rather than /usr/bin. This, of course, depends on where these unix executables are found in your system, so for readers other than the OP, you'll need to use the directory that holds your desired version of python.
This PATH will remain valid through the rest of your R session. To change your path in all R sessions, update (or create, if you haven't yet) your .Rprofile file. An .Rprofile file can be (or go) in your HOME directory or R_HOME. If you add the above line to .Rprofile, each time R is initialized, they will execute at the beginning of each R session.

Adding the ibapi library to PYTHONPATH module in Spyder (Python 3.6)

I am trying to simply connect to the ibapi (Interactive Brokers API), but I am having some technical troubles with Spyder.
What I did so far:
I installed the latest version for Windows from here
I provided the following path to the PYTHONPATH manager in Spyder: C:\TWS API\source\pythonclient\ibapi afterwards I restarted Spyder
When I simply type import ibapi I get the same error message: ModuleNotFoundError: No module named 'ibapi'
What I am doing wrong here and how can I fix this simple error?
I don't use python very much but I'm pretty sure you have to install the ibapi. I never used the PYTHONPATH and mine works fine in Spyder and Jupyter. I'm using Anaconda.
I run the Anaconda prompt (just activates the conda environment) and navigate to the dir C:\TWS API\source\pythonclient and run python setup.py install
Then everything works. I think many python packages need to be installed like this.
note: That's not my install dir, I just copied yours. There may be a problem with a space in the path. Try renaming to C:\TWSAPI\... if you still have a problem.
Note: after python setup.py install, you might need to restart spyder. If doesn't help, then copy the newly-created ibapi folder to:
C:\Users\iuzeri\AppData\Local\Programs\Python\Python37-32\Lib\site-packages
or
C:\Program Files (x86)\Python37-32\Lib\site-packages
copy your ibapi here
C:/ProgramData/Anaconda3/Lib/site-packages/ibapi

jupyter notebook not running through command line [duplicate]

I have installed Jupyter on Windows 10, Python 3.x via
$ pip install jupyter
The installation works fine, even though I did restart the terminal.
But trying to run
$ jupyter notebook
gives the following error
'jupyter' is not recognized as an internal or external command, operable program or batch file.
How and where do I find the executable for Jupyter?
If you are absolutely sure that your Python library path is in your system variables (and you can find that path when you pip install Jupyter, you just have to read a bit) and you still experience "command not found or recognized" errors in Windows, you can try:
python -m notebook
For my Windows at least (Windows 10 Pro), having the python -m is the only way I can run my Python packages from command line without running into some sort of error
Fatal error in launcher: Unable to create process using ' "
or
Errno 'THIS_PROGRAM' not found
Please try either of these commands first;
$ py -m notebook
$ python -m notebook
for jupyterlab users
py -m jupyterlab
Otherwise
$ python -m pip install jupyter --user
$ jupyter notebook
If this does not work.
pip does not add jupyter directly to path for local.
The output from
$ which python
/c/Users/<username>/AppData/Local/Programs/Python/Python35-32/python
After some digging I found a executable for jupyter in the folder:
C:\Users\<username>\AppData\Roaming\Python\Python35\Scripts\jupyter.exe
Difference between local and roaming folder
So if you want to be able to execute a program via command line, you need to add it into the %PATH variable. Here is a powershell script to do it. BE SURE TO ADD THE ";" before adding the new path.
$ [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\<username>\AppData\Roaming\Python\Python35\Scripts", [EnvironmentVariableTarget]::User)
Update:
if you are using python3, switch out python with python3
but I encourage you to use pyenv instead :)
I had the exact same problem and it was driving me crazy. Other answers provide a solution, but they don't explain why you and I are having this problem.
I will try to explain why this is happening and then provide some solutions.
You can go to the end to see the TL;DR.
1)What's going on? Why is this error happening?
I'll try to make a step-by-step answer so everything is explained clearly.
If you think it's too basic at the beginning, go to the end of this "article".
I'll first start with common things like running the python shell from the terminal or running pip. You'll see why you can do that from the terminal and we'll end up on why and how you can run the jupyter notebook from the terminal as well.
Ready? Let's start!
Have you ever wondered why you can type python in the terminal (command prompt) and suddenly start the Python interpreter?
Microsoft Windows [Version 10.0.18363.1440]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\YOUR-USERNAME>python
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
You probably already know (but maybe don't) that this is because Python was added to the Windows PATH environment variable. You probably did it at installation time or afterwards.
But, what is this PATH environment variable?
It basically allows you to run any executables, that are located inside
the paths specified in the variable, at the command prompt without
having to give the full path to the executable.
You can check the content of that PATH variable with:
>>> import sys
>>> for path in sys.path:
print(path)
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\lib
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\lib\site-packages
... (some other paths were taken out for clarity)
You can see this folder: C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39. This is the place where Python version 3.9 is installed. Let's check its content:
<DIR> DLLs
<DIR> Doc
<DIR> etc
<DIR> include
<DIR> Lib
<DIR> libs
<DIR> Scripts
<DIR> share
<DIR> tcl
<DIR> Tools
LICENSE.txt
NEWS.txt
python.exe
python3.dll
python39.dll
pythonw.exe
vcruntime140.dll
vcruntime140_1.dll
Voilà! We have the python.exe file (an executable). We have a Python executable file in the PATH, that's why you can start the Python interpreter from the terminal with just typing python. If this wasn't the case you would have to type the full path to the executable file in the terminal:
C:\Users\YOUR-USERNAME> C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\python)
Instead of just:
C:\Users\YOUR-USERNAME> python
And what about when you use pip?
It's the same principle. You can run pip from the terminal because there is a pip executable file in the PATH variable.
If you go to C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Scripts\ (which is in the PATH showed above) you'll see many executables files. One of them is pip. Actually I have three versions: pip, pip3.9 and pip3.
The Scripts folder allows exectuable files to be run from the terminal. Like pip or other libraries that you intend to run directly from the terminal. The Scripts folder:
...is not intended for you, it's for scripts that are installed as
components of modules that you install. For example, pip is a module,
but it also has a wrapper script by the same name, pip, which will be
installed in that directory.
If you put something there and it is properly in your PATH, then it
should be executable
That wrapper script would be the pip executable file. When this executable file is run, it locates the pip folder in the Python installation folder and runs pip.
But you could also run pip directly from the installation folder (C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Lib\site-packages), without needing the executable pip file.
But, how can you do it?
I'm glad you ask. There is a Python way to run modules as the main module (without the need to import it).
python -m pip
When you run a module directly its name becomes __main__. What -m does is:
Search sys.path for the named module and execute its contents as the __main__ module.
What is __main__?
'__main__' is the name of the scope in which top-level code executes.
A module’s __name__ is set equal to '__main__' when read from standard
input, a script, or from an interactive prompt.
...
I guess that the pip executable does something similar, or at least, has the same effect: to start pip.
2)What does this have to do with the Jupyter Notebook?!
Think of the Jupyter Notebook as the same as pip. If you want to run jupyter in the terminal, you need an executable that it's on the PATH.
We have already seen that the executables of modules like pip or jupyter are located here C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Scripts\.
If I check the content of the folder I see this:
easy_install-3.9.exe
easy_install.exe
f2py.exe
jsonschema.exe
jupyter-bundlerextension.exe
jupyter-console.exe
jupyter-nbconvert.exe
jupyter-nbextension.exe
jupyter-notebook.exe
jupyter-qtconsole.exe
jupyter-serverextension.exe
jupyter-trust.exe
pip.exe
pip3.9.exe
pip3.exe
I see the already mentioned pip, pip3.9 and pip3. But I don't see jupyter (the word "jupyter" alone).
If I type jupyter in the terminal I get the error that started all:
'jupyter' is not recognized as an internal or external command, operable program or batch file.
Finally we've reached an answer to your question!!!
'jupyter' is not recognized as a command because there is no executable file in the Scripts folder called jupyter.
So, let's try a different executable. What about jupyter-notebook?
BINGO! The notebook is running!
Serving notebooks from local directory:
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Scripts
Jupyter Notebook 6.3.0 is running at:
http://localhost:8888/?token=... (edited)
or http://127.0.0.1:8888/?token=... (edited)
Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
I don't know why I don't have a jupyter executable called 'jupyter'. The official documentation says to use jupyter notebook on the terminal, but it seems that in some cases it doesn't work. And I think it has to do with what I mentioned above: there is no jupyter exectuable in the Scripts folder.
If you remember, I told you that you can run pip as the main module using python -m pip.
It happens that you can do the same with jupyter.We just need to know how to call it. As in with pip, we have to check the folder where 3rd party libraries are installed: C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Lib\site-packages.
You'll see jupyter_console, but this just creates an interactive notebook in the terminal, not exactly what you were looking for. You're also going to find folders ending with .dist.info, like jupyter_console-6.4.0.dist-info. This is just metadata of the Wheel Binary Package builder. You'll also see a folder like jupyterlab_pygments, but that's for JupyterLab. We want to use the classic Jupyter notebook.
What we want is to run notebook. How do we know this?
You'll see in the folder site-packages the folder (package) notebook. Inside there is a file called __main__.py:
#__main__.py
if __name__ == '__main__':
from notebook import notebookapp as app
app.launch_new_instance()
It's calling notebookapp.py which is a "A tornado based Jupyter notebook server." Yes, this is what we need.
We can see that launch_new_instance in the notebookapp calls launch_instance(), which "launches an instance of a Jupyter Application".
Perfect! We are in the correct folder. To run the jupyter notebook from the Python interactive shell we have to run the notebook package with:
python -m notebook
3)*** SUMMARY: SOLUTION ***
tl;dr:
I have explained and showed why this error is happening.
Now let's summarize the solutions:
To know the name of the jupyter executable (in the Scripts folder), so you can run directly from the terminal (Command Prompt) as:
jupyter notebook
or as:
jupyter-notebook
Or whatever name you have.
Run the notebook as the main module from Python:
python -m notebook
I hope this helps you as much as it helped me. I'm open to your comments and suggestions.
I had the same problem, but
py -m notebook
worked for me.
I got Jupyter notebook running in Windows 10. I found the easiest way to accomplish this task without relying upon a distro like Anaconda was to use Cygwin.
In Cygwin install python2, python2-devel, python2-numpy, python2-pip, tcl, tcl-devel, (I have included a image below of all packages I installed) and any other python packages you want that are available. This is by far the easiest option.
Then run this command to just install jupyter notebook:
python -m pip install jupyter
Below is the actual commands I ran to add more libraries just in case others need this list too:
python -m pip install scipy
python -m pip install scikit-learn
python -m pip install sklearn
python -m pip install pandas
python -m pip install matplotlib
python -m pip install jupyter
If any of the above commands fail do not worry the solution is pretty simple most of the time. What you do is look at the build failure for whatever missing package / library.
Say it is showing a missing pyzmq then close Cygwin, re-open the installer, get to the package list screen, show "full" for all, then search for the name like zmq and install those libraries and re-try the above commands.
Using this approach it was fairly simple to eventually work through all the missing dependencies successfully.
Cygwin package list
Once everything is installed then run in Cygwin goto the folder you want to be the "root" for the notebook ui tree and type:
jupyter notebook
This will start up the notebook and show some output like below:
$ jupyter notebook
[I 19:05:30.459 NotebookApp] Serving notebooks from local directory:
[I 19:05:30.459 NotebookApp] 0 active kernels
[I 19:05:30.459 NotebookApp] The Jupyter Notebook is running at:
[I 19:05:30.459 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Copy/paste this URL into your browser when you connect for the first time, to login with a token:
http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
In Python 3.7.6 for Windows 10. After installation, I use these commands.
1. pip install notebook
2. python -m notebook
OR
C:\Users\Hamza\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts
.
For my pc python-scripts are located in the above path. You can add this path in environment variables. Then run command.
1. jupyter notebook
You can add the following to your path
C:\[Python Installation path]\Scripts
e.g. C:\Python27\Scripts
It will start working for jupyter and every other pip install you will do here on.
Check whether you have given python PATH in environmental variables properly.
If not, then set python path. Then use:
$ python -m notebook
If you are using the Anaconda distribution, make sure when installing it that you check the "Change PATH" option.
first you should make sure that you are put your python path in your system variables ..
Then try run this
python -m pip install jupyter --user
and then
run this
py -m notebook or jupyter notebook
In Windows 10 you can use ipython notebook. It works for me.
I added
c:\users\[user]\appdata\roaming\python\python37\site-packages
to the path and it worked.
## windows CMD
for default install (just check "add path" and "next" when installing)
python -m notebook
for custom install in C:\
jupyter notebook
Problem for me was that I was running the jupyter command from the wrong directory.
Once I navigated to the path containing the script, everything worked.
Path-
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts
I have two python version installed:
1. Python 3.8.2: This was installed independently
2. Python 3.7.6: This was installed along with Anaconda 3
Multiple versions caused conflict even after setting the path variables correctly.
I have uninstalled the Python 3.8.2 and after restart, the command
jupyter notebook
Worked perfectly :)
you can create a batch file and search for Jupiter in your windows search and ooen its properties and you will get this string.
D:\anaconda3\python.exe D:\anaconda3\cwp.py D:\anaconda3 D:\anaconda3\python.exe D:\anaconda3\Scripts\jupyter-notebook-script.py "%USERPROFILE%/"
after getting this you can create a jupitor.bat file with this content it that
and you can save that file in a script folder in d or any drive and add the path of your script file in your environmental path
and then you can easly call this by typing jupitor in cmd.
To install I used
"pip install notebook" in windows command line
To run python -m notebook did not work for me, but python3 -m notebook worked
First run this command
pip install jupyter
then add system variable path , this path is where jupyter and other scripts are located
PATH = C:\Users<userName>\AppData\Roaming\Python\Python38\Scripts
e.g PATH=C:\Users\HP\AppData\Roaming\Python\Python38\Scripts
After that we can run jupyter from any folder/directory
jupyter notebook
I just found that error when I first intalled and run the jupyter notebook. Then I found the executable (.exe) file from
C:\Users\<user-name>\AppData\Local\Programs\Python\Python39\Scripts.
The actual file name was "jupyter-notebook".
The installation guide says it as "jupyter notebook" to run the server. You have to run the command "jupyter-notebook" in the command line and it will be run. Thanks!
My problem was my user's folder had a space in folder name.
After creating a new user and switching to that windows user, windows shortcuts and links from within' Anaconda worked fine.
Windows 8.1 64 Bit. Latest Anaconda.
Note: I ended up uninstalling an reinstalling Anaconda but my sense is the problem was really just the space in the windows user username/user folder.
Using python 3.6.3. Here after installing Jupyter through command 'python -m pip install jupyter', 'jupyter notebook' command didn't work for me using windows command prompt.
But, finally 'python -m notebook' did work and made jupyter notebook to run on local.
http://localhost:8888/tree
Here is how I resolved stated issue, hope it helps:
install python 3.7 using official website for python, while installing include installing PATH by checking it's box
after that open cmd (be sure to open it after step 1) and write: pip install jupyter ENTER
now you should be able to open jupyter notebook by using command: jupyter notebook
Seems simple, but it may as well help.
In windows 10:
If you used anaconda3 for Jupyter notebook installation and forgot to check the box to add the environment variables to the system during installation, you need to add the following environment variables to the "Path" variable manually:
(search windows settings for Edit environment variables")
Environment variables for Anaconda3
If you have installed jupyter with
"python -m pip install jupyter" command
instead of
"$ pip install jupyter" command
then follow these steps:
Create a notepad
Change its extension from ".txt" to ".ipynb"
Right click it and click "open with"
In the pop up, go to - C:\Users\<"windows_user_name">\AppData\Roaming\Python\Python38\Scripts
Click on "jupyter-lab.exe"
100% working solution:
Follow these steps:
Open the folder where you downloaded "python-3.8.2-amd64.exe" setup or any other version of python package
Double click on "python-3.8.2-amd64.exe'
Click "Modify"
You will see "Optional features"
Click "next"
Select "Add python to environment variables"
Click "install"
Then u can run jupyter in any desired folder u desire
E.g open "cmd" command prompt
Type :
E:
E:\>jupyter notebook
It will get started without showing
'Jupyter' is not recognized
Thanks
I was facing the same issue in windows7, as i just recoverd my computer with the help of recovery point and after that notebook just stopped working. I tried to change the path setting but nothing was working so I just simply uninstalled the python with the application from which it was installed and after that I installed it again. After that I installed jupyter notebook again and then it worked fine.
Thanks
I just installed JupyterLab on top of my Python 3.8/pip enabled Win10 machine, so I ran into these startup problem with windows.
If everything is ok (check that you have PATH for Python, eg. C:\Users[Username]\AppData\Local\Programs\Python\Python38-32\Scripts) you simply run:
jupyter-lab.exe
and that's it.
Cheers
Add system variable path, this path is where jupyter and other scripts are located
PATH -->
`C:\Users\<userName>\AppData\Roaming\Python\Python39\Scripts`
Like in my laptop PATH is:
"C:\Users\developer\AppData\Roaming\Python\Python39\Scripts"
After that, You will be able to run jupyter from any folder & any directory by running the below command
jupyter notebook
Had the same issue. Finally searched where jupyter.exe directory was located on my computer. For some reason it was under
C:\VTRoot\HarddiskVolume4\Users[user]\AppData\Local\Programs\Python
Whereas the Python is
C:\Users[user]\AppData\Local\Programs\Python
So I copied full Python39 folder from VTRoot to main Python39 python folder in AppData. And the issue is solved.
First check where your python is installed by heading over to
C:\Users\**username**\AppData\Local\Programs\Python\Python39\Scripts
this is the path usually you will find python installed. After this type in
cd.. to get one step out of the Scripts folder
After this install jupyter in here using:
$ pip install jupyter
The installation was fine and when I tried to open the jupyter notebook, it gave me the following error.
'jupiter is not recognized as an internal or external command, operable program or batch file.
I checked a lot of resources but still, I faced the same problem. After doing a lot of stuff from the internet, I myself figured out that maybe due to some updates(for some users) it won't open by typing the command
jupyter notebook
Instead, you have to type
jupyter-notebook
The only thing I was missing was this Hyphen-minus. Hope this works for you too.

Running R from Mac OSX terminal

I've searched the web, and I'm still unclear on how to run R from the Mac terminal. I have Rstudio and the standalone R app installed. I thought I could just type "R" from the command line as I do with "python", but that doesn't work. Is it necessary to edit the PATH in my bash profile? If so, how do I give the correct location of R?
Thanks for any help
Edits after receiving comments
So, I'm running Sierra, and when I type "r" or "R" at the terminal, I get "-bash: R: command not found." If I type, "which R" in the terminal I do not get any output.
Here is the output from "echo $PATH": /usr/local/heroku/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/samuelcolon/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0/bin:/Users/samuelcolon/.rvm/gems/ruby-2.1.0#global/bin:/Users/samuelcolon/.rvm/rubies/ruby-2.1.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/samuelcolon/.rvm/bin:/Users/samuelcolon/.rvm/bin
As for the installation, I believe I downloaded it directly from cran.r-project.org a while ago. I can locate the GUI in my applications and open it--
I have version 3.13. Is it possible, I only have R.app installed but not R? Perhaps that's the reason I'm getting the 'command not found' when typing "R" into the terminal?
Generally, I've been working in RStudio, but I'd still like to access R from the terminal and also to find where things are located. I'm fine with removing and re-installing R if it's easiest to start from square one. I hope the extra detail helps, and I appreciate the responses.
An answer for those not that familiar with Terminal and Bash.
I have done a fresh update install of R from the R.org cran site as part of seeking an answer to your question.
I found this latest install version 3.4.0 installs R for access in Terminal, and also installs R.app as part of the package.
To my understanding, reading support docs, if you have an older version of R it will update that. However it will not update an installation of R installed by the anaconda package.
Where are the R files stored?
I can only assume that with a fresh install of the latest R, R will work for you in Terminal.
To learn where the R files are that are being accessed - in Terminal after starting R, and in R.app, type:
>R.home()
In my case as example:
In R.app - the R version 3.4.0 is accessed in the top directory (not my user folder):
R.home()
[1] "/Library/Frameworks/R.framework/Resources"
In Terminal - the R version 3.3.2 is accessed in the Anaconda package, again in the top level directory.
R.home()
[1] "/anaconda/lib/R"
So I have two different versions of R, and Terminal accesses a different version to R.app.
How can I ensure I access the same version in Terminal as I do in the R.app?
For someone familiar with bash, and how the whole bash command system works I am sure there is a well constructed command. All the same here are some novice solutions.
-
• First Solution:
I could update the anaconda version, however, I would prefer not to as as other elements of the anaconda package my depend on this older version of R. For those not yet familiar with Terminal and bash, not such a novice solution.
-
• Second Solution:
This solution came from mko. It provides a single use solution. From the result above, and checking the directory structure a little further to find this R file.
Finding the significant R file enables me to edit an extension of the above path shown in the R.app. So add /bin/R to enter
/Library/Frameworks/R.framework/Resources/bin/R
Entering and pressing return will start R from this version.
Alternatively, one can find this file and icon in the GUI Finder, lead by the above result, and just double click on it, and it will open Terminal and a session with R running for you. Easy!
One could also make an alias of it and put it on your desktop for easy future starts.
-
• Third Solution:
My last solution I think may be best, adding to mko's solution. Make an alias.
Being in my home directory in Terminal I open .bash_profile using the nano text editor. (If you do not already know how to do this, then best not use this solution.)
I then add the line in this env file.
alias Rv340='/Library/Frameworks/R.framework/Resources/bin/R'
I then save the changes and exit this terminal session. I then open a new Terminal window. (This is so the changes to the env above are incorporated in the new terminal session).
Then when I enter the alias:
Rv340
The version of R I want opens.
You can choose a different alias name to "Rv340".
-
• Fourth Solution:
A second more permanent solution for opening the same version of R in Terminal is as follows.
Copy the path as showing in R.app in response to the R.home() command above, and add that path to PATH in your .bash_profile. (If you do not know already how to do this, then ignore this solution.) Do so as follows.
export PATH="/Library/Frameworks/R.framework/Resources:$PATH"
To my understanding, this ensures that bash looks here for R (and anything else), then moves on to the other paths in PATH. Since this adds this path to the beginning of $PATH, an env variable, bash looks here first where it finds the newer version first, and stops looking.
When it comes to understanding PATH in the env set up in .bash_profile the following two links were helpful.
About PATH.
How to correctly add a path to PATH.
This solution may muck with anaconda's invocation of R. I have yet to check this.
First of all, you have to start terminal application. You can use either built in Terminal.app, or you can use replacement. My favorite one is iTerm2
https://www.iterm2.com
Then, you simply open terminal window and run R. Just like shown below:
Have fun with R!
Just ran into the same issue when installing R-4.0.3.pkg on my MacBook (MacOS BigSur). Can open R.app to the clunky R GUI, but typing in 'R' in terminal doesn't work.
Turns out, an R executable lives here: /Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R
So I added this alias to my newly created .zshrc script:
alias R '/Library/Frameworks/R.framework/Versions/4.0/Resources/bin/R'
Now when I type in R, it opens... I swear this all happened seamlessly in earlier versions.
There is currently a bug in CRAN's R installation package that results in it not correctly installing symbolic links to R and Rscript for commandline use. I've just verified this by inspecting the postflight script in their 4.0.5 installation package. This only impacts MacOS system releases of 20 and above (you can check with uname -r).
I've included more info here, along with what the "correct" fix should be: manually creating symbolic links to /usr/local/bin that point to the R and Rscript binaries themselves. If this is the current challenge, then this would be a far better solution to creating aliases or manipulating PATH in various ways, since it's what the installation package intended to do (and presumably will again soon).
R: command not found
In short, if this is the problem, then Ashkan Mirzaee's answer (https://stackoverflow.com/a/67202173/2093929) to create the symbolic links directly is correct in form, but might not have the right link command. The 4.0.5 package intends instead to use:
mkdir -p /usr/local/bin
cd /usr/local/bin
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
You can create a symbolic link from R and Rscript binaries to /usr/local/bin to add them to the PATH:
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/R /usr/local/bin
sudo ln -s /Library/Frameworks/R.framework/Versions/Current/Resources/bin/Rscript /usr/local/bin
Now which R should return /usr/local/bin/R and you can use R.
An easy way to open RStudio with admin privilege on macOS:
Go to Applications, then right click on RStudio
Select "Show Package Contents"
Go to Contents/MacOS
Now open terminal(in bash mode). Type sudo and drag the RStudio.exec into terminal and press on ENTER
Now RStudio will have admin access!

Adding PATH to RStudio’s path

I am running RStudio on MacOS and need to use some custom command line tools like csvcut (part of csvkit) for a function that multiple people on our team will use on their machines.
If I run a system('pip install csvcut) (I am using this command as an example; normally, I’d run csvcut) from R in the terminal, it works (checks if the last version has been installed, etc.), just like if I do it from the command line terminal.
If I do the same thing from within RStudio:
> system('pip install csvkit')
sh: pip: command not found
If I do which pip in the terminal and copy-paste the address into RStudio, it works:
system('/anaconda3/anaconda/bin/pip install csvkit')
Requirement already satisfied (use --upgrade to upgrade): csvkit in /anaconda3/anaconda/lib/python3.4/site-packages
# etc.
^ that’s the output if I simply do system('pipinstall csvkit') from R in the terminal.
Unfortunately, I can’t even run which pip from within RStudio. (Also, I couldn’t automatically pip install csvkit for others’ machines, since it requires sudo access.) If there was a way to point RStudio to R’s path, that would be easier.
I found instructions on some website that said to create a .Renviron file and have a R_LIBS_USER=~/R/library line in it, but that didn’t help.
Try adding this line to your .Renviron file:
PATH=/anaconda3/anaconda/bin:$PATH

Resources