通过Anaconda提示符vs CMD运行Python/Pickle

2024-03-29 14:12:33 发布

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

下面是我尝试使用命令行我收到的错误

Microsoft Windows [Version 10.0.17134.765]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 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.
>>> import sys
>>> for p in sys.path: print(p)
...

C:\Users\Garrett\Anaconda3\python37.zip
C:\Users\Garrett\Anaconda3\DLLs
C:\Users\Garrett\Anaconda3\lib
C:\Users\Garrett\Anaconda3
C:\Users\Garrett\AppData\Roaming\Python\Python37\site-packages
C:\Users\Garrett\Anaconda3\lib\site-packages
C:\Users\Garrett\Anaconda3\lib\site-packages\win32
C:\Users\Garrett\Anaconda3\lib\site-packages\win32\lib
C:\Users\Garrett\Anaconda3\lib\site-packages\Pythonwin
>>> import pickle
>>> import os
>>> import sys
>>> filename_FB = 'C:/xampp/htdocs/PD/model/final_gam_FB.sav'
>>> pitchType = 'FB'
>>> V = 90
>>> HB = 12.66
>>> VB = 4.5
>>> U = 0.3
>>> appr_diff = -1.17
>>> with open(filename_FB,'rb') as file: loaded_model_FB = pickle.load(file)
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Garrett\Anaconda3\lib\site-packages\pygam\__init__.py", line 7, in <module>
    from pygam.pygam import GAM
  File "C:\Users\Garrett\Anaconda3\lib\site-packages\pygam\pygam.py", line 10, in <module>
    import numpy as np
  File "C:\Users\Garrett\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\Garrett\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
>>>

下面是我使用Anaconda提示符成功运行相同代码的尝试。你知道吗

(base) C:\Users\Garrett>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path: print(p)
...

C:\Users\Garrett\Anaconda3\python37.zip
C:\Users\Garrett\Anaconda3\DLLs
C:\Users\Garrett\Anaconda3\lib
C:\Users\Garrett\Anaconda3
C:\Users\Garrett\AppData\Roaming\Python\Python37\site-packages
C:\Users\Garrett\Anaconda3\lib\site-packages
C:\Users\Garrett\Anaconda3\lib\site-packages\win32
C:\Users\Garrett\Anaconda3\lib\site-packages\win32\lib
C:\Users\Garrett\Anaconda3\lib\site-packages\Pythonwin
>>> import pickle
>>> import os
>>> import sys
>>> filename_FB = 'C:/xampp/htdocs/PD/model/final_gam_FB.sav'
>>> pitchType = 'FB'
>>> V = 90
>>> HB = 12.66
>>> VB = 4.5
>>> U = 0.3
>>> appr_diff = -1.17
>>> with open(filename_FB,'rb') as file: loaded_model_FB = pickle.load(file)
...
>>>

我正在用VSCode运行我的自动脚本,它使用CMD作为终端,我更愿意保持这种方式。这个过程在Jupyter笔记本中也起作用。你知道吗


Tags: inimportfblibpackagessyslinesite