2

我在 Amazon sagemaker 中有以下生命周期配置文件

#!/bin/bash
sudo -u ec2-user -i <<'EOF'

source activate conda_pytorch_p36

# Replace myPackage with the name of the package you want to install.
conda install -c pytorch torchtext
# You can also perform "conda install" here as well.

source deactivate

EOF

但是,当我尝试在 pytorch_conda_p36 虚拟环境中的 jupyter 笔记本上导入 torchtext 时,我得到一个找不到模块的错误

这是我的代码

from sagemaker import get_execution_role

role = get_execution_role()
bucket='sagemaker-us-east-2-964130302244'
data_dir = 'dataset'
data_location = 's3://{}/{}'.format(bucket, data_dir)

import torch
import torch.utils.data as tud
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from collections import Counter, defaultdict
import operator
import os, math
import numpy as np
import random
import copy
import s3fs
import torchtext
fs = s3fs.S3FileSystem()

我得到的错误如下

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-c9a96a48b0b7> in <module>
     11 import copy
     12 import s3fs
---> 13 import torchtext
     14 fs = s3fs.S3FileSystem()
     15 # from nltk import word_tokenize

ModuleNotFoundError: No module named 'torchtext'
4

0 回答 0