1

Every time I install Anaconda on a new computer, I am having this environment setting problem. I am using a Mac computer. I successfully installed Anaconda but I still have problems running Jupyter Notebook. When I go to terminal, it starts with no environment and when I type python, this is the output:

Last login: Fri Oct 11 22:47:17 on ttys000

username@Users-MacBook-Pro ~ % python

WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Aug 24 2019, 18:37:03) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin
Type "help", "copyright", "credits" or "license" for more information.

However, I installed Anaconda 3.7 and the folder directory is: /Users/username/anaconda3. When I type: source .bash_profile, this activates the (base) environment and lets me open jupyter notebook. But, I do not want to remember this command all the time. Instead, I want to be able to type jupyter notebook and have it opened when I open a terminal. Can you please enlighten me?

Thanks!

tcokyasar
  • 582
  • 1
  • 9
  • 26
  • 1
    What shell are you using? The `.bash_profile` will get sourced automatically if you are using `bash`, but if something else, you need to run the specific init for it. For example, if `zsh`, then running once `conda init zsh` will configure the appropriate init script. – merv Oct 12 '19 at 04:10
  • @merv, it worked perfectly. I did not even know it was using `zsh`. Thanks a lot! – tcokyasar Oct 12 '19 at 04:24
  • 1
    Also, in new versions of anaconda, you need to type `python3`, even if you have your virtual env (with Python3) activated. – Scott Skiles Oct 12 '19 at 05:01
  • @ScottSkiles I've never heard this before. Could you please link documentation for this? – merv Oct 12 '19 at 16:28
  • @merv https://stackoverflow.com/a/48178776/992432 – Scott Skiles Oct 13 '19 at 02:46
  • @ScottSkiles Is that the correct link? - there's no mention of having to use `python3` on that page. [The Anaconda docs](https://docs.anaconda.com/anaconda/user-guide/getting-started/#start-python) illustrate that `python` is sufficient to start a Python session within an activated env. – merv Oct 13 '19 at 03:01
  • Looks like you're right, they must have updated it so that `python` gets the same version as the environment installed. See below for more detail. – Scott Skiles Oct 13 '19 at 04:09
  • I recommend closing this as a duplicate of [How to run Conda?](https://stackoverflow.com/questions/18675907/how-to-run-conda). I expanded [my answer there](https://stackoverflow.com/a/55526573/570918) to explicitly mention other shells, so I think it covers the case here. – merv Oct 15 '19 at 13:10

1 Answers1

-1

You do not activate a conda environment with: source .bash_profile. You do so by typing conda activate <your_env_name>.

You say:

However, I installed Anaconda 3.7 and the folder directory is: /Users/username/anaconda3. When I type: source .bash_profile, this activates the (base)

For the problems you're running into I'd recommend using a conda virtual environment. Long story short you can control what versions of your libraries are installed and which version of Python you use.

In the latest version of conda, conda 4.7.12, you have the option of using either Python2 or Python3. If you type python or python3 you get a Python3 interpreter. If you type python2 you get the Python2 interpreter. If your Python3 virtualenv and you type jupyter notebook it will open a notebook using Python3. Screenshots below to demonstrate.

Following this answer (derived from the conda docs on creating a new virtualenv) we can create a new virtual env with Python 3.6.2:

conda create -n py37 python=3.7

NOTE: Below my version of Python is 3.6.2

Then the steps below show the differences in commands:

enter image description here

This DigitalOcean tutorial has some exhaustive steps on setting up Jupyter Notebook for Python3, but after running jupyter notebook you should be able to choose from the dropdown New which env you want to use.

All of the above should reliably solve all the problems you're facing.

Scott Skiles
  • 3,647
  • 6
  • 40
  • 64
  • Maybe my question was not clear, but this was not my concern. When I open the terminal, it was not starting with an environment like `(py36)` in your case. My problem was to stick to a single environment every time I open the terminal. The default environment is `(base)` and that was what I wanted to use. The comment of @merv was perfectly the answer. – tcokyasar Oct 14 '19 at 01:24
  • Once you are in the environment and type `python` it brings the `Python 3.7` which is what I am using. But, when I search for `python` out of an environment, it gives me `Python 2.7`. So, not only your answer is not helpful but also it is misleading. – tcokyasar Oct 14 '19 at 01:27
  • This is by design. If you do not activate a virtual environment you get python2. – Scott Skiles Oct 17 '19 at 03:19