从外壳程序外部调用Python解释器时找不到包

从外壳程序外部调用Python解释器时找不到包

本文介绍了Anaconda:从外壳程序外部调用Python解释器时找不到包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Anaconda环境:

I have two Anaconda environments:

  • 基本环境
  • R环境(仅包含R)

基本环境是默认环境,不会出现在Anaconda子目录envs中.默认情况下,Base已激活,尤其是在执行以下命令时.

The base environment is the default environment and does not appear in the Anaconda subdirectory envs. Base is activated by default and in particular while the commands below are executed.

当我从Anaconda提示符(或我为Anaconda配置的另一个提示符)中运行python时,导入numpy不会出现问题.

When I run python from within the Anaconda prompt (or another prompt that I have configured for Anaconda), importing numpy works without problems.

但是,当我从IDE运行脚本时(C:\my\path\to\Anaconda3\python.exe myscript.py),numpy的导入失败.因此,我已经通过pip安装了numpy,结果安装失败.现在import numpy结果

However, when I run my scrips from my IDE (exctuing C:\my\path\to\Anaconda3\python.exe myscript.py), the import of numpy fails. Therefore, I have installed numpy through pip and ended up with a broken installation. import numpy results now in

Traceback (most recent call last):
  File "D:\GoogleDrive\_Backup\Programmieren\Datathlon\econ_model.py", line 1, in <module>
    import numpy as np
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

据我所知,问题是由于使用了不同版本的numpy引起的. (不过,我想要启用了mkl的版本).

As far as I know the issue is due to different versions of numpy being used. (I want the mkl-enabled version, though).

找不到正确版本的numpy让我猜测我以某种方式拥有多个python环境,而我的IDE调用了错误的环境.我不知道这怎么可能,因为Anaconda是PC上唯一的python资源.

That the right version of numpy is not found lets me guess that I have multiple python environments somehow and that the wrong one is called by my IDE. I have no idea how this can be possible, as Anaconda is the only python resource on my PC.

如何从anaconda提示符外部调用正确的python版本?如何配置python/Anaconda默认调用正确的版本?

How can I call the right python version from outside of the anaconda prompt? How can I configure python/Anaconda that the correct version is called by default?

我知道激活 shell时,激活基本环境可以解决问题.但是,如果我运行一个命令,即在不打开外壳的情况下仅调用python脚本,我将无法激活任何内容(可以吗?).

I am aware that activating the base environment solves the problem when working within a shell. But if I run a single command, i.e. just call the python script without opening a shell before, I cannot activate anything (can I?).

技术细节:

  • Python 3.7
  • conda版本4.6.8 win-64
  • Windows 10 64位
  • IDE:带有PyDev的Eclipse

推荐答案

您可以conda activate myEnvName.然后,在shell上调用python将为您带来所需的python.安装软件包时,请始终选择要在哪个环境中安装软件包.默认环境为base

You can conda activate myEnvName. Then, calling python on shell will bring you the desired python. When installing packages, always select in which environment you wish it to be installed. The default environment is base

这篇关于Anaconda:从外壳程序外部调用Python解释器时找不到包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 10:58