繁体   English   中英

如何执行 python.exe 来打开它,就像我从名为“base”的 anaconda 环境中打开它一样?

[英]How can I execute python.exe to open as if I opened it from the anaconda environment named “base”?

文件路径:“C:\Users\Disander\anaconda3\python.exe”

当我从上面的路径打开 python 时, python 显示以下警告:

Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>>                                                                   

然后,当我尝试导入 numpy 或 pandas 时,会引发以下错误:

Traceback (most recent call last):
  File "C:\Users\Disander\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\Users\Disander\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
    from . import overrides
  File "C:\Users\Disander\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Disander\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\Disander\anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.7 from "C:\Users\Disander\anaconda3\python.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: DLL load failed: The specified module could not be found.

>>>    

如果我从 anaconda 终端启动 python,python 工作得很好。 我通过导入 numpy 和 pandas 来展示这一点。 我导入 sys 并打印 sys.executable 以显示 anaconda 正在使用相同的 python 可执行文件 python.exe。

(base) C:\Users\Disander>python
Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
C:\Users\Disander\anaconda3\python.exe
>>>
>>> import numpy
>>> import pandas
>>>     

我还尝试在执行 python.exe 后激活(基础)环境。 下面,我展示了当我尝试使用“os.system('conda activate base')”时发生的情况

>>> import os
>>> os.system('conda activate base')
'conda' is not recognized as an internal or external command,
operable program or batch file.
1
>>>   

我想知道是否有办法执行 python.exe 文件,就像我使用(基本)环境从 anaconda 执行它一样。 我需要这个,因为我有另一个依赖于这个可执行文件的应用程序。 同一个应用程序使用它来导入模块,例如 numpy 和 pandas,但它不起作用。

您首先需要确保“Scripts”文件夹在您的路径环境中(C:\Anaconda3\Scripts,用于我的设置)。 然后

activate environment_name 

在 CMD 中应该可以工作。 如果要激活“base”,请将“environment_name”替换为“base”。

打开 Anaconda 提示符或 conda conda activate 然后通过打印路径环境到控制台

(base) C:\> path

将 Anaconda 安装文件夹..\Anaconda3\下面列出的每个文件夹添加到您的用户环境PATH变量中。 这将允许 Python 也可以找到 numpy 的 C 库。

\Anaconda3;
\Anaconda3\Library\mingw-w64\bin;
\Anaconda3\Library\usr\bin;
\Anaconda3\Library\bin;
\Anaconda3\Scripts;
\Anaconda3\bin;

当然,这一切都破坏了 conda 精心设计的环境概念。 因此,请确保您知道自己在做什么。

问题编辑后编辑:

如果您有另一个依赖于 Python 在 Anacoda 环境中运行的应用程序 - 例如 PowerBI 桌面 - 只需从 Anaconda 提示符运行该其他应用程序。

在第二个问题编辑后编辑

如果无法从os识别conda ,您显然错过了通过以下方式初始化 shell

conda init --all

基本上这是在默认情况下在 Anaconda 安装期间完成的,但有些人出于某种原因更喜欢跳过这一步。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM