导入psutil会导致ImportError

时间:2017-09-11 10:50:12

标签: python python-import psutil

我正在尝试让psutil在我们的服务器上运行。它正在运行AIX。没有pip。所以,我将repo from github(psutil的AIX构建版),cd下载到其中,并运行了Python CLI。

现在,尝试执行import psutil会导致ImportError。

bash-4.2$ python
Python 2.7.5 (default, Aug 16 2013, 14:02:06) [C] on aix6
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "psutil/__init__.py", line 163, in <module>
    from . import _psaix as _psplatform
  File "psutil/_psaix.py", line 20, in <module>
    from . import _psutil_aix as cext
ImportError: cannot import name _psutil_aix
>>> import psutil              ## IMPORTING AGAIN THE SAME SESSION CAUSES DIFFERENT ERROR
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "psutil\__init__.py", line 39, in <module>
    from . import _common
ImportError: cannot import name _common

我可以在这做什么?使用python setup.py install --user在本地安装模块也无效:

bash-4.2$ python setup.py install --user
running install
running build
running build_py
running build_ext
building 'psutil._psutil_aix' extension
xlc_r -ma -I/opt/freeware/include -DAIX_GENUINE_CPLUSCPLUS -Wl,-brtl -g -DNDEBUG -O2 -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=532 -DPSUTIL_AIX=1 -I/opt/freeware/include/python2.7 -c psutil/_psutil_common.c -o build/temp.aix-7.1-2.7/psutil/_psutil_common.o
unable to execute xlc_r: No such file or directory
error: command 'xlc_r' failed with exit status 1

我尝试使用完全运行的tweepy包(同时sixrequestsrequests_oauthlib已安装)。

编辑:只是为了说明这不仅限于AIX,我尝试在Windows上做同样的事情,它也会出现同样的错误。

2 个答案:

答案 0 :(得分:0)

可能的解决方案可以从PyPi下载 (psutil on PyPi

然后用zip程序(7zip或类似程序)打开它。 应该有一个psutil文件夹。将此文件夹放在脚本旁边,然后尝试导入它。

答案 1 :(得分:0)

psutil目前不支持AIX,尽管它将在下一个主要版本中使用。