用 Anaconda 安装了一个包,无法在 Python 中导入

问题描述

原谅我,但我是 python 新手.我已经使用安装了一个包(theano)conda install theano,当我输入conda list,包就存在了

Forgive me but I'm new to python. I've installed a package (theano) using conda install theano, and when I type conda list, the package exists

但是,当我通过运行 python 进入 python 解释器,并尝试使用 import theano 导入它时,我得到一个错误:no module named theano",当我列出所有 python 模块时,theano 不存在.

However, when I enter the python interpreter by running python, and try to import it with import theano, I get an error: "no module named theano", and when I list all python modules, theano doesn't exist.

我错过了什么?


解决方案

可能是因为您的计算机中安装了多个 python 环境.当您执行 which python 时,您可能会在计算机中安装本机 python.即 /usr/bin/python

Probably due to the fact you have multiply python envs installed in your computer. when you do which python you will probably get the native python installed in your computer. that is /usr/bin/python

您想使用安装 Anaconda 时附带的 Python.只需将 Anaconda 路径添加到 $PATH 的开头即可.(为了做到这一点,您可能需要编辑您的 ~/.bashrc 文件(或您的 shell 的等效文件),然后编辑 source ~/.bashrc.

You want to use the Python that came when you installed Anaconda. Just add Anaconda path to the beginning of your $PATH. (In order to do this you probably need to edit your ~/.bashrc file (or the equivalent file for your shell) then source ~/.bashrc.

下次你会运行 pythonimport theano 你会成功.

Next time you will go to will run python and import theano you'll succeed.

相关文章