簡體   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