Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use the default Python rather than the Anaconda installation when called from the terminal

I recently installed the Anaconda version of Python. Now when I type python into the terminal it opens the Anaconda distribution rather than the default distribution. How do I get it to use the default version for the command python on Linux (Ubuntu 12.04 (Precise Pangolin))?

like image 321
Michael Avatar asked Jul 09 '14 21:07

Michael


People also ask

Can you use Python without Anaconda?

You can use conda without Anaconda, but using Anaconda always involves the conda tool. module load python/3.4. x-anaconda Python 3 is the latest version of the language and python 2 is considered legacy. Generally you should choose Python 3 for new projects whenever possible.

What is the default Python version in Anaconda?

Anaconda supports Python 3.7, 3.8, 3.9 and 3.10. The current default is Python 3.9.

Does Anaconda install Python by default?

Installing the Anaconda platform will install the following: Python; specifically the CPython interpreter that we discussed in the previous section. A number of useful Python packages, like matplotlib, NumPy, and SciPy. Jupyter, which provides an interactive “notebook” environment for prototyping code.

Why is Anaconda preferred for Python installation?

Anaconda is popular because it brings many of the tools used in data science and machine learning with just one install, so it's great for having short and simple setup. Like Virtualenv, Anaconda also uses the concept of creating environments so as to isolate different libraries and versions.


2 Answers

Anaconda adds the path to your .bashrc, so it is found first. You can add the path to your default Python instance to .bashrc or remove the path to Anaconda if you don't want to use it.

You can also use the full path /usr/bin/python in Bash to use the default Python interpreter.

If you leave your .bashrc file as is, any command you run using python will use the Anaconda interpreter. If you want, you could also use an alias for each interpreter.

You will see something like export PATH=$HOME/anaconda/bin:$PATH in your .bashrc file.

So basically, if you want to use Anaconda as your main everyday interpreter, use the full path to your default Python or create an alias. If you want it the other way around, remove the export PATH=.... from bashrc and use full path to Anaconda Python interpreter.

like image 151
Padraic Cunningham Avatar answered Oct 16 '22 01:10

Padraic Cunningham


Having tried all the suggestions so far, I think modifying the export statement in file ~/.bashrc, as Piotr Dobrogost seems to suggest, is the best option considering the following:

  • If you remove the whole statement, you have to use full paths for Conda binaries.
  • Using Conda 4.4.10 links in the directory anaconda/bin/ point to binaries in the same directory, not the system ones in /usr/bin.
  • Using this approach you get the system programs for all that have been previously included in $PATH and also the ones specific to anaconda without using full paths.

So in file ~/.bashrc instead of

# Added by the Anaconda3 4.3.0 installer export PATH="/home/user/anaconda3/bin:$PATH" 

one would use

export PATH="$PATH:/home/user/anaconda3/bin" 
like image 28
Asta86 Avatar answered Oct 16 '22 01:10

Asta86