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

2024-05-07 23:40:04 发布

您现在位置:Python中文网/ 问答频道 /正文

文件路径:“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工作得非常好。我用importin 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后激活(base)环境。下面,我展示了当我尝试使用“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文件,就像我使用(base)环境从anaconda执行它一样。我需要这个,因为我有另一个应用程序依赖于这个可执行文件。同一个应用程序使用它来导入模块,如numpy和pandas,但它不起作用


Tags: orinfromcoreimportnumpyyouline
2条回答

您首先需要确保“脚本”文件夹位于path环境中(对于我的设置,C:\Anaconda3\Scripts)。 然后

activate environment_name 

在CMD中应该可以工作。如果要激活“基础”,请将“环境名称”替换为“基础”

打开Anaconda提示符或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;

当然,这一切都破坏了康达精心阐述的环境概念。所以要确保你知道你在做什么

问题编辑后编辑:

如果您有另一个依赖于Python的应用程序在Anacoda环境中运行,例如PowerBI Desktop,那么也可以从Anaconda提示符运行另一个应用程序

在第二个问题编辑后编辑

如果conda无法从os中识别,则显然无法通过初始化shell

conda init all

基本上,默认情况下,这是在Anaconda安装期间完成的,但有些人出于任何原因宁愿跳过这一步

相关问题 更多 >