1

I wanted to be able to use both python 2.x and 3.x so I installed multiple kernels as follows, as per the instructions in this question (Using both Python 2.x and Python 3.x in IPython Notebook)

To configure the python2.7 environment:

conda create -n py27 python=2.7`
source activate py27`
conda install notebook ipykernel`
ipython kernel install --user

and

To configure the python3.5 environment:

conda create -n py35 python=3.5
source activate py35
conda install notebook ipykernel
ipython kernel install --user

Now I can choose between python 2 and 3 in the notebook. But when I tried to import either numpy or pandas I get the import error

Import error:No module named numpy

I tried to uninstall Anaconda and reinstall it and then install jupyter notebook, NOW I Cannot even start jupyter notebook it says 'Kernel Error'

Can some one please help me out?

Community
  • 1
  • 1
vishmay
  • 386
  • 2
  • 4
  • 15

3 Answers3

1

You need to do the following in each environment:

conda install numpy

You could also have done this on creation:

conda create -n py35 python=3.5 notebook ipykernel numpy
Neapolitan
  • 2,101
  • 9
  • 21
  • May be I am missing something here .. But already had anaconda installed before I made these changes and numpy and pandas were both installed with it? When I run conda list in console .. both modules are listed – vishmay May 22 '16 at 17:55
  • 3
    When you make a new environment in conda, that has its own set of packages installed. You created two new environments to run IPython kernels in, but you didn't install numpy in those environments. It's still installed in your 'root environment', but you didn't set the kernels up to run in that. You can install a kernel from your root environment by running `ipython kernel install --user` *without* activating another environment. – Thomas K May 22 '16 at 22:42
  • Could you please clarify what you mean by installing numpy "in each environment"? How? I had Python 3 and just added Python 2, but can't see NumPy or Pandas libraries in Jupyter. Should I run the following? conda create -n py27 python=2.7 notebook ipykernel numpy – John Strong Jun 10 '17 at 00:44
  • You cannot have "added Python 2" to a python 3 environment. An environment is a python interpreter and a set of packages in site-packages. Anaconda has a base environment which is used if you have not 'activated' a virtual environment. I'm guessing you updated your base environment so that it uses python 2 instead of python 3? Anyway, you want to create a new environment using the command line that you have given, then you want activate that environment by typing "activate py27" in the anaconda console window. – Neapolitan Jun 12 '17 at 13:56
  • If you have other scripts that require python 3, then you can create another environment such as py35. To run the python 3 scripts you will have to activate the py35 environment first. – Neapolitan Jun 12 '17 at 13:56
0

This is on a mac os but could apply:

There is an application called Anaconda Navigator. In this application there is a tab named Environments, if you switch to that tab you can switch between (Anaconda) environments (kernels) and see which packages are installed. You can also by change the dropdown from installed to not installed apply/install new python packages.

0

I first installed Anaconda 2. Since I wanted to have kernels for both Python 2.7 and Python 3.6, I created an environment called ipykenel_py3. Like you, pandas nor numpy would import when I ran python in the kernel for python 3. This is apparently because we need to install them to the new environment ourselves. To do this, type the following from the condas command line (from the same directory where your Anaconda is stored):

conda install -n ipykernel_py3 pandas

spacedustpi
  • 351
  • 5
  • 18