简体   繁体   English

模块在 Anaconda 提示符下工作,但在 Spyder 中不工作

[英]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.

相关问题 如果在 anaconda 提示符下运行没有问题,但是 ModuleNotFoundError: No module named &#39;keras&#39; in Spyder - It's OK if run in anaconda prompt but ModuleNotFoundError: No module named 'keras' in Spyder 从 Anaconda 提示符启动 Spyder - Launching Spyder from Anaconda prompt 在 Anaconda 之外的 Spyder 中找不到模块 - Module not found in Spyder outside of Anaconda 使用 spyder (python) 中的 xport 模块将 XPT 文件转换为 CSV 时出错,但在 anaconda 提示符中没有错误 - Error in converting XPT file to CSV using xport module in spyder (python), but no error in anaconda prompt 从命令提示符执行 .py 文件引发“ImportError:没有名为 geopandas 的模块”- 脚本在 Spyder 中工作(使用 anaconda) - Executing .py file from Command Prompt raises “ImportError: no module named geopandas”- Script works in Spyder (using anaconda) 在Spyder IDE(或Anaconda3 Prompt)上运行Pyinstaller - Running Pyinstaller on Spyder IDE (or Anaconda3 Prompt) Python 模块请求在 anaconda 提示符下工作但不在 Windows 10 命令行中工作 - Python module requests working in anaconda prompt but not in windows 10 command line ModuleNotFoundError:anaconda spyder 中没有名为“pyLDAvis”的模块 - ModuleNotFoundError: No module named 'pyLDAvis' in anaconda spyder 无法在 anaconda (Spyder) 中为 python 安装 googleads 模块 - Unable to install the googleads module for python in anaconda (Spyder) 安装在 Anaconda 中的模块,与 Spyder 相同的解释器,但 Spyder 得到“ModuleNotFoundError” - Module installed in Anaconda, same interpreter with Spyder yet Spyder gets “ModuleNotFoundError”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM