我在AWS上运行一个EC2实例,使用python包时出错。我已经使用pip
安装了psutil
和stanfordcorenlp
,但当我尝试导入时,我收到了以下错误:
>>> from stanfordcorenlp import StanfordCoreNLP
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/maxio-efs/stanfordcorenlp/__init__.py", line 1, in <module>
from stanfordcorenlp.corenlp import StanfordCoreNLP
File "/home/ec2-user/maxio-efs/stanfordcorenlp/corenlp.py", line 14, in <module>
import psutil
File "/home/ec2-user/maxio-efs/psutil/__init__.py", line 99, in <module>
from . import _pslinux as _psplatform
File "/home/ec2-user/maxio-efs/psutil/_pslinux.py", line 26, in <module>
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux' from 'psutil' (/home/ec2-user/maxio-efs/psutil/__init__.py)
即使导入psutil
似乎也不起的作用
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/maxio-efs/psutil/__init__.py", line 99, in <module>
from . import _pslinux as _psplatform
File "/home/ec2-user/maxio-efs/psutil/_pslinux.py", line 26, in <module>
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux' from 'psutil' (/home/ec2-user/maxio-efs/psutil/__init__.py)
我尝试过很多解决方案,包括安装python-devel
。我该如何解决此问题?
我在错误的目录中执行代码。我安装了一个名为maxio-efs
的EFS,其文件结构为:
SSH POINT/
maxio-efs/
stanfordcorenlp
psutil
(other python packages)
上述错误仅在从maxio-efs
目录内的运行python脚本时发生。我需要在其他地方,以便python能够找到正确的包。通过从与maxio-efs
相同的目录级别运行python脚本,问题消失了。