[英]A module is working in Anaconda prompt, but not in Spyder
I have been fighting with this problem for hours now, and it's a kind of complicated one.几个小时以来,我一直在与这个问题作斗争,这是一个复杂的问题。 I'm on windows 7, Python 2.7, Spyder 3.2.6 I tried to install OSMNX through
cygwin
, however I faced many issues.我在 windows 7、Python 2.7、Spyder 3.2.6 我试图通过
cygwin
安装OSMNX ,但是我遇到了很多问题。 Finally managed to install it through windows cmd. Through the anaconda prompt
, I could import the osmnx
with no error.终于成功通过windows cmd安装了。通过
anaconda prompt
,我可以顺利导入osmnx
。
However, I'm trying to import it in spyder, but I keep receiving:但是,我试图在 spyder 中导入它,但我不断收到:
Traceback (most recent call last):追溯(最近一次通话):
File "<ipython-input-2-2b99ab66aebb>", line 1, in <module>
import osmnx
ImportError: No module named osmnx
What is exactly wrong here?这里究竟出了什么问题? and how can I solve it?
我该如何解决?
The problem is the use of different environments for your anaconda prompt and your instance of spyder, as mentioned by @Simon. 问题是你的anaconda提示和spyder实例使用不同的环境,正如@Simon所提到的那样。 This problem and the different available solutions are reviewed here: GitHub discussion
这里回顾了这个问题和不同的可用解决方案: GitHub讨论
You can solve the problem as follows. 您可以按如下方式解决问题。 Provided that you have the package
spyder-kernels
already installed in your Anaconda prompt environment, run the following command in Anaconda prompt: 如果您已在Anaconda提示环境中安装了
spyder-kernels
软件包,请在Anaconda提示符中运行以下命令:
python -c "import sys; print(sys.executable)"
and copy the path returned to your console. 并复制返回到控制台的路径。 Then, in Spyder go to Tools>Preferences>Python interpreter .
然后,在Spyder中转到工具>首选项> Python解释器 。 Here you will see two options under Select the Python interpreter for all Spyder consoles .
在这里,您将看到为所有Spyder控制台选择Python解释器下的两个选项。 Check the second option and paste the path you copied from the Anaconda prompt.
检查第二个选项并粘贴从Anaconda提示中复制的路径。 Close Spyder and open it again and now the
import module
command should work. 关闭Spyder并再次打开它,现在
import module
命令应该可以工作。
By doing this, Spyder will basically use the Python interpreter from the environment in which you have installed the new modules. 通过这样做,Spyder将基本上使用您安装新模块的环境中的Python解释器。
You need to sync the environment variables/path for both.您需要同步两者的环境变量/路径。
Just go to the anaconda promt and enter the command只需 go 到 anaconda promt 并输入命令
> conda install spyder
It will automatically prepare the environment.它会自动准备环境。 Following that, just open up spyder and execute your code.
之后,只需打开 spyder 并执行您的代码。
I have faced the same problem. 我遇到了同样的问题。 I have installed the Spyder and Jupyter inside the conda environment.
我在conda环境中安装了Spyder和Jupyter。 After that it's working fine for me.
之后它对我来说很好。
source activate my_conda_env
conda install spyder
conda install jupyter notebook
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.