VSCode中的“ MemoryError”,但Jupyter / AnacondaPrompt中没有

时间:2019-07-10 15:53:03

标签: python memory visual-studio-code

我在MNIST数据集上的split_train_test函数的Python实现中遇到了大约2 GB的MemoryError。

任务管理器几乎不能达到最大内存的50%,包括在我的计算机上打开的其他应用程序。我有16GB的RAM。

我看到大多数人都指向64 vs 32 bit或python 2 vs 3问题;但是,我的VS Code和Windows 10均为64位,然后查看>命令面板> Python:选择解释器显示我正在使用anaconda3 / conda中的Python 3.7.1 64位。

我知道代码本身可以工作,因为导入py文件后,我已经在Jupyter中使用了输出。

    def split_train_val(val_frac=0.3, size=1):
        """Splits training and validation set

        param val_frac: fraction of total training set to be used for validation
        """
        # Read converted csv
        X_raw = pd.read_csv('Data/csv/X_train.csv')
        Y_raw = pd.read_csv('Data/csv/y_train.csv')

        # Rename Label column, concat to X set
        Y_raw.columns = ['Label']
        df = pd.concat([Y_raw, X_raw], axis=1).sample(frac=size)

        # Split training set into train and val
        N = df.shape[0] 
        n = round(val_frac * N)
        train = df.iloc[n:,:]
        val = df.iloc[:n,:]

        x_train = train.drop(['Label'], axis=1)
        x_val = val.drop(['Label'], axis=1)
        y_train = train.Label
        y_val = val.Label


        # Return training and validation set
        return(x_train, y_train, x_val, y_val)


    x_train, y_train, x_val, y_val = split_train_val()

错误消息:

Traceback (most recent call last):
  File "preprocessing.py", line 71, in <module>
    x_train, y_train, x_val, y_val = split_train_val()
  File "preprocessing.py", line 53, in split_train_val
    df = pd.concat([Y_raw, X_raw], axis=1).sample(frac=size)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\reshape\concat.py", line 229, in concat
    return op.get_result()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\reshape\concat.py", line 426, in get_result
    copy=self.copy)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals\managers.py", line 2052, in concatenate_block_managers
    values = values.copy()
MemoryError

最后,我尝试按照某些VS Code文档的建议将jedi.memoryLimit设置更改为-1。这也没有帮助。

我导入然后在Jupyter中运行该功能。我也在Anaconda Prompt中运行了此确切代码。它们均不会导致任何错误。

1 个答案:

答案 0 :(得分:0)

VS Code和Windows 10可能是64位的,但是Python的安装是32位的,如路径C:\Users\...\AppData\Local\Programs\Python\Python37-32\所示。尝试显式安装64位版本的Python,并确保在VS Code中选择它。