2

I installed Anaconda3 so I can create environments and install different packages in each environment. But I fail to understand the difference between the Python in

/usr/bin/python

and

/opt/anaconda3/bin/python

I can seem to access Python 3.6.5 Anaconda from both, why is that? And, what is the difference between both?

Furthermore, I would like to install packages to a single Python environment only.

  • 1
    just activate the environment, then `pip install` installs the packages only in that environment. Notice that you have to run spyder from the conda command line or it will automatically loads the root environment. – anishtain4 Jun 08 '18 at 14:19
  • thanks ! what about the difference between /usr/bin/python and /opt/anaconda3/bin/python ? how are both of these connected –  Jun 08 '18 at 14:21

4 Answers4

1

When you are running python in the terminal, it is looking up your default path to your the python command. In this case, anaconda probably put a line in your shell profile specify the path to the anaconda version, which is why you are seeing it in the interpreter when you run python from either directory.

Secondly, you can set up a conda environment to download app specific dependencies without interfering with your default set up by

conda create --name myenv
source activate myenv
conda install packagename

This will install it in the myenv environment only. To deactivate the environment just run

source deactivate

Here is the documentation on that https://conda.io/docs/user-guide/tasks/manage-environments.html

gymbrane
  • 167
  • 9
  • thank you! I managed to create the environment and install the package but I still cannot seem to get it to work. Check the updated version please –  Jun 08 '18 at 15:02
  • yeah, so once you have created an environment, you will need to activate it in your shell environment. In your shell, run `source activate pythonoozie` and then run `conda install pandas` from the shell. – gymbrane Jun 08 '18 at 16:16
  • yes I did that already, but it seems like I cannot point oozie to that python envirnment –  Jun 08 '18 at 16:20
  • i am just curious, when you run this command in the shell `conda env list` does it put the asterisk next to the `envs/pythonoozie` – gymbrane Jun 08 '18 at 16:51
0

Judging by your path, you are using Linux which comes with python installed. So /usr/bin/python is default and you have installed the other one later.

For the environments use https://conda.io/docs/user-guide/tasks/manage-environments.html to activate the desired environment, then you can pip install or conda install the packages and it will be places safely only in that environment. Note that spyder icon runs the root environment by default and you have to run it from terminal after activating one of the environments.

Edit:

I'm not sure why you want to use cd to change the python version. I suggest use aliases. I guess you are just changing the path but running the same version of the python anyway. Take a look at this question: Two versions of python on linux. how to make 2.7 the default

anishtain4
  • 2,342
  • 2
  • 17
  • 21
0

I wanted to create a new virtual environment to install new packages. Following worked for me:

Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)

Upgrade pip:

!pip install --upgrade pip

Install virtual environment:

!pip install virtualenv

Select version of Python you want to use in new environment:

I wanted to create an environment with Python version 3. Naming it as Python3_xyz:

!virtualenv -p python3 Python3_xyz

After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)

Create a new option with the name of the created environment

And finally, run the following command:

!python -m ipykernel install --user --name=Python3_xyz

This will create a new option with the name Python3_xyz in the menu from where we create a new notebook.

NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.

Yogesh Awdhut Gadade
  • 2,498
  • 24
  • 19
0

This question is bit dated, but since I faced a similar issue, what worked for me might help someone!

I did pip install requests from within my conda environment, but failed to import requests even after trying out everything.

What worked for me: run python -m pip install requests or python3 -m pip install requests within you environment. This installed requests successfully for me.

Binit Bhagat
  • 181
  • 1
  • 5