Conda安装的包,Python找不到
问题描述
我尝试安装 Anaconda 的 Theano.它可以工作,但是当我输入 python -i 时,import theano
显示 No module named 'theano'
.我是否需要切换另一个 Python 解释器,如何?另外,对于 conda 安装的包,如果我不重复安装它们,我可以在 Python 中找到吗?Python 与 Anaconda 的 Python 有什么关系?谢谢!!!
I try to install Theano by Anaconda. It works, but when I enter the python -i, import theano
shows No module named 'theano'
. Do I need to switch another interpreter of Python, how? Also, for the packages installed by conda, if I don't double install them, can I find in Python? How is Python related to Python by Anaconda? Thanks!!!
解决方案
我遇到了类似的问题,尝试安装 folium.如果您使用的是Anaconda:
I had have a similar issue, trying to install folium. If you are using the Anaconda:
当你使用conda install -c conda-forge folium
安装时,包会放在:
When you install using conda install -c conda-forge folium
, the package will be placed in:
./anaconda3/envs/[name env]/lib/python3.7/site-packages/folium
当您使用 pip 安装时(激活 anaconda env),pip install folium
,包将被放置在:
When you install using pip (with a anaconda env activated), pip install folium
, the package will be placed in:
./anaconda3/lib/python3.7/site-packages/folium
Python首先使用sites-packages作为手动构建python包的目标目录.当您从源代码构建和安装 python 包时(使用 distutils,可能通过执行 python setup.py install ),默认情况下您会在 site-packages 中找到已安装的模块.
Python use first the sites-packages as the target directory of manually built python packages. When you build and install python packages from source (using distutils, probably by executing python setup.py install ), you will find the installed modules in site-packages by default.
在这种情况下,您有两个位置:/anaconda3/lib/python3.7/site-packages/
和 /anaconda3/envs/[name env]/lib/python3.7/site-packages/
.
In this case you have two places: /anaconda3/lib/python3.7/site-packages/
and /anaconda3/envs/[name env]/lib/python3.7/site-packages/
.
首先,这些模块将在 /anaconda3/lib/python3.7/site-packages/
中默认可用.有时(我真的不知道为什么)sites-packages conda env 中的模块在不导出 PATH 的情况下无法自动导入.
First the modules will be available as default in /anaconda3/lib/python3.7/site-packages/
. Sometimes (and I really don't know why) the modules inside sites-packages conda env are not available to import automatically without export the PATH.
所以,要解决这个问题,你有两个选择:
So, to solve this issue, you have 2 options:
使用
pip install folium
安装并导入 folium(不需要通过 conda install 安装),或
Installing using
pip install folium
and import folium (don't need install by conda install), or
在 conda install 之后,运行 conda init
,关闭终端并打开一个新终端.所以,尝试再次导入.
After conda install , run conda init
, close the terminal and open a new one. So, try to import again.
这里是一些关于使用 pip inconda 环境.
Here are some tips about use a pip in a conda-environment.
相关文章