由Conda安装的软件包,Python找不到它 [英] Package installed by Conda, Python cannot find it

查看:839
本文介绍了由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使用 first 首先将sites-packages用作手动构建的python软件包的目标目录.从源代码构建和安装python软件包时(使用distutils,可能通过执行python setup.py install),默认情况下,您会在站点软件包中找到已安装的模块.

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/中作为默认设置提供.有时(我真的不知道为什么),如果没有导出PATH,将无法自动导入sites-packages conda env内的模块.

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.

因此,要解决此问题,您有2个选择:

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之后,运行conda init,关闭终端并打开一个新终端.因此,请尝试再次导入.

After conda install , run conda init, close the terminal and open a new one. So, try to import again.

这是有关使用pip的一些技巧在conda环境中.

Here are some tips about use a pip in a conda-environment.

这篇关于由Conda安装的软件包,Python找不到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆