简体   繁体   English

代码可在 Anaconda 上运行,但不能通过 cmd 在 Python 上运行

[英]Code works on Anaconda but not on Python through cmd

I have code that runs over 7000 columns dataset with around 250k records我有运行超过 7000 列数据集的代码,大约有 250k 条记录

it works fine when I use Anaconda Spyder当我使用 Anaconda Spyder 时它工作正常

but now I want to put this code to run based on Task Schedule但现在我想根据任务计划运行此代码

Therefore I am want to execute the code in cmd Command Prompt as因此我想在 cmd 命令提示符中执行代码作为

Python "c:\myfolder\predservice.py"

It didn't work as Task Schedule它不能作为任务计划工作

I start tracing the problem by running the script on Python from within cmd我通过在 cmd 中在 Python 上运行脚本来开始跟踪问题

I got this error, which I did not get when I was running through Spyder我遇到了这个错误,这是我在运行 Spyder 时没有遇到的

How can I avoid such error我怎样才能避免这样的错误

I thought it is because of the memory.我以为是内存的原因。 when i select a subset of the dataset it runs fine but when I run the whole dataset i get this error当我选择数据集的一个子集时它运行良好但是当我运行整个数据集时我收到此错误

>>> df =pd.concat([df.drop('PreviousDRGs', 1), pd.get_dummies(df['PreviousDRGs'] .str.split(",", expand=True), prefix
 = 'PreviousDRGs').max(level=0, axis=1).asty pe(np.int8)], axis=1)


 Traceback (most recent call last):   File "<stdin>", line 1, in
 <module>   File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py",
 line 11616, in stat_func return self._agg_by_level(name, axis=axis,
 level=level, skipna=skipna)   


 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py",
 line 10440, in _agg_by_level grouped = self.groupby(level=level,
 axis=axis, sort=False)   


 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py",
 line 7894, in groupby **kwargs   



 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\groupby\groupby.py",
 line 2522, in groupby return klass(obj, by, **kwds)   



 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\groupby\groupby.py",
 line 363, in __init__ obj._consolidate_inplace()   



 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py",
 line 5252, in _consolidate_inplace self._protect_consolidate(f)   



 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py",
 line 5241, in _protect_consolidate result = f()   




 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\generic.py",
 line 5250, in f self._data = self._data.consolidate()   



 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals\managers.py",
 line 932, in consolidate bm._consolidate_inplace()   





 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals\managers.py",
 line 937, in _consolidate_inplace self.blocks =
 tuple(_consolidate(self.blocks))   




 File
 "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals\managers.py",
 line 1913, in _consolidate list(group_blocks), dtype=dtype,
 _can_consolidate=_can_consolidate   



 File "C:\Users\decisionsupport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals\blocks.py",
 line 3323, in _merge_blocks new_values = new_values[argsort]   
 numpy.core._exceptions.MemoryError: Unable to allocate array with
 shape (4524, 1 38299) and data type uint8
>>> 

Looks like Anaconda may be using a 64-bit python. 看起来Anaconda可能正在使用64位python。 Your error traceback shows that your Task Scheduler is running your .py script using a 32-bit python. 您的错误回溯表明您的任务计划程序正在使用32位python运行.py脚本。 Either 要么

  1. replace your 32-bit python with a 64-bit version 用64位版本替换您的32位python
  2. or install a separate 64-bit python and tell Task Scheduler to use that to run your .py file. 或安装一个单独的64位python,并告诉Task Scheduler使用它来运行.py文件。

I think you need to activate your conda base in cmd before calling the script我认为您需要在调用脚本之前在 cmd 中激活您的 conda base

call <path>\anaconda\Scripts\activate base
<path>\anaconda\python.exe <path>\scriptname.py

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

相关问题 通过anaconda提示符执行python代码时,导入numpy起作用,但通过cmd运行时产生错误 - Import numpy works when python code executed through anaconda prompt but produces an error when run through cmd 通过 Windows cmd 在 Anaconda 环境中运行 python 脚本 - Running python scripts in Anaconda environment through Windows cmd 在cmd中使用Anaconda Python - Using Anaconda Python in cmd 代码适用于Jupyter(Anaconda),但不适用于普通的Python-为什么 - Code works with Jupyter(Anaconda) but not with normal Python - WHY 在python中运行CMD代码行,在终端Anaconda中查看结果 - Run CMD code line in python, see results in terminal Anaconda Python 底图脚本与 Anaconda cmd 提示符一起运行,但不与 VS Code 一起运行 - Python Basemap script runs with Anaconda cmd prompt but not with VS Code 在cmd中运行python和anaconda python - Run python and anaconda python in cmd Python 代码适用于 cmd 和 VScode 但不适用于 powershell 或 pyinstaller - Python code works on cmd and VScode but not on powershell or pyinstaller Jupyter 笔记本无法通过 anaconda promot 或 cmd 加载 - Jupyter notebook not loading through anaconda promot or cmd 导入h2o在anaconda cmd上失败,但在Windows cmd上有效? - import h2o fails on anaconda cmd but works on windows cmd ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM