my jupyter notebook fails to import anaconda modules consistently

耗尽温柔 提交于 2019-12-01 01:36:28

Deleting everything Python related is a bad idea. There are system files which require it. Hopefully you didn't delete the wrong files and won't have to reinstall your operating system.

Regarding your question, you need to first activate your conda environment before launching jupyter notebook.

To see which environment you already have installed, type the following from a terminal window:

conda info --envs

Then type the following to activate your environment (obviously my_env is the name of what ever your environment is).

source activate my_env

From here, you are in your conda environment. To open Jupyter notebook, just type:

jupyter notebook

This notebook will be linked to your conda environment and will have access to all modules therein (type conda list from the terminal once you've activated your environment per above to see them, or !conda list from within the notebook).

Just for fun, we'll create a quick environment named test_env.

conda create -n test_env pandas jupyter notebook qtconsole matplotlib
source activate test_env
jupyter notebook  # launches your notebook

Alternatively, to launch qtconsole:

jupyter qtconsole

Although we only installed a few packages, all linked dependencies are also installed (including numpy). This is now the output of conda list:

$ conda list
# packages in environment at /usr/local/miniconda/envs/test_env:
#
appnope                   0.1.0                    py27_0    defaults
backports-abc             0.4                       <pip>
backports.ssl-match-hostname 3.4.0.2                   <pip>
backports_abc             0.4                      py27_0    defaults
cycler                    0.10.0                   py27_0    defaults
decorator                 4.0.9                    py27_0    defaults
freetype                  2.5.5                         0    defaults
ipykernel                 4.3.1                    py27_0    defaults
ipython                   4.1.2                    py27_0    defaults
ipython-genutils          0.1.0                     <pip>
ipython_genutils          0.1.0                    py27_0    defaults
ipywidgets                4.1.1                    py27_0    defaults
jinja2                    2.8                      py27_0    defaults
jsonschema                2.4.0                    py27_0    defaults
jupyter                   1.0.0                    py27_1    defaults
jupyter-client            4.1.1                     <pip>
jupyter-console           4.1.0                     <pip>
jupyter-core              4.0.6                     <pip>
jupyter_client            4.1.1                    py27_0    defaults
jupyter_console           4.1.0                    py27_0    defaults
jupyter_core              4.0.6                    py27_0    defaults
libpng                    1.6.17                        0    defaults
markupsafe                0.23                     py27_0    defaults
matplotlib                1.5.1               np110py27_0    defaults
mistune                   0.7.1                    py27_0    defaults
mkl                       11.3.1                        0    defaults
nbconvert                 4.1.0                    py27_0    defaults
nbformat                  4.0.1                    py27_0    defaults
notebook                  4.1.0                    py27_0    defaults
numpy                     1.10.4                   py27_0    defaults
openssl                   1.0.2g                        0    defaults
pandas                    0.17.1              np110py27_0    defaults
path.py                   8.1.2                    py27_1    defaults
pexpect                   3.3                      py27_0    defaults
pickleshare               0.5                      py27_0    defaults
pip                       8.0.3                    py27_0    defaults
ptyprocess                0.5                      py27_0    defaults
pygments                  2.1.1                    py27_0    defaults
pyparsing                 2.0.3                    py27_0    defaults
pyqt                      4.11.4                   py27_1    defaults
python                    2.7.11                        0    defaults
python-dateutil           2.4.2                    py27_0    defaults
python.app                1.2                      py27_4    defaults
pytz                      2015.7                   py27_0    defaults
pyzmq                     15.2.0                   py27_0    defaults
qt                        4.8.7                         1    defaults
qtconsole                 4.1.1                    py27_0    defaults
readline                  6.2                           2    <unknown>
setuptools                20.1.1                   py27_0    defaults
simplegeneric             0.8.1                    py27_0    defaults
singledispatch            3.4.0.3                  py27_0    defaults
sip                       4.16.9                   py27_0    defaults
six                       1.10.0                   py27_0    defaults
sqlite                    3.9.2                         0    defaults
ssl_match_hostname        3.4.0.2                  py27_0    defaults
terminado                 0.5                      py27_1    defaults
tk                        8.5.18                        0    http://repo.continuum.io/pkgs/free/osx-64/tk-8.5.18-0.tar.bz2
tornado                   4.3                      py27_0    defaults
traitlets                 4.1.0                    py27_0    defaults
wheel                     0.29.0                   py27_0    defaults
zlib                      1.2.8                         0    <unknown>

Once done, deactivate the environment.

source deactivate  # From within the terminal of the active environment.

If you'd like to delete it:

conda env remove -n test_env
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!