Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use psutil on OS X #577

Closed
amjith opened this issue Jan 30, 2015 · 4 comments
Closed

Unable to use psutil on OS X #577

amjith opened this issue Jan 30, 2015 · 4 comments
Labels

Comments

@amjith
Copy link

amjith commented Jan 30, 2015

I'm on OS X 10.9.5 with a brew installed Python 2.7.9.

I installed psutil using pip install psutil and installation succeeds. But when I try it use it I get the following error.

$ python -c 'import psutil'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/psutil/__init__.py", line 149, in <module>
    import psutil._psosx as _psplatform
  File "/usr/local/lib/python2.7/site-packages/psutil/_psosx.py", line 168, in <module>
    pids = cext.pids
AttributeError: 'module' object has no attribute 'pids'

Do I need to do something special to get this working in OS X

@giampaolo
Copy link
Owner

Mmm... that is weird. It looks like psutil wasn't properly installed.
What's the output of:

import _psutil_linux as cext
print(dir(cext))
print(cext.version)

Also, I would try to uninstall and reinstall.
If that won't work I would try to install psutil from sources.

@amjith
Copy link
Author

amjith commented Jan 30, 2015

I tried uninstalling and then reinstalling, no luck. I tried the commands you listed, here's the output.

Since I'm on OS X I replaced import _psutil_linux as cext with import _psutil_osx as cext.

$ python                                                                                                                                                                                             [22:00:19]
Python 2.7.9 (default, Jan 21 2015, 16:28:02)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _psutil_osx as cext
>>> print(dir(cext))
['PSUTIL_CONN_NONE', 'SIDL', 'SRUN', 'SSLEEP', 'SSTOP', 'SZOMB', 'TCPS_CLOSED', 'TCPS_CLOSE_WAIT', 'TCPS_CLOSING', 'TCPS_ESTABLISHED', 'TCPS_FIN_WAIT_1', 'TCPS_FIN_WAIT_2', 'TCPS_LAST_ACK', 'TCPS_LISTEN', 'TCPS_SYN_RECEIVED', 'TCPS_SYN_SENT', 'TCPS_TIME_WAIT', '__doc__', '__file__', '__name__', '__package__', 'get_disk_io_counters', 'get_disk_partitions', 'get_net_io_counters', 'get_num_cpus', 'get_pid_list', 'get_process_cmdline', 'get_process_connections', 'get_process_cpu_times', 'get_process_create_time', 'get_process_cwd', 'get_process_exe', 'get_process_gids', 'get_process_memory_info', 'get_process_memory_maps', 'get_process_name', 'get_process_num_ctx_switches', 'get_process_num_fds', 'get_process_num_threads', 'get_process_open_files', 'get_process_ppid', 'get_process_status', 'get_process_threads', 'get_process_tty_nr', 'get_process_uids', 'get_swap_mem', 'get_system_boot_time', 'get_system_cpu_times', 'get_system_per_cpu_times', 'get_system_users', 'get_virtual_mem']
>>> print(cext.version)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'version'
>>> print(cext.version())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'version'
>>>

@giampaolo
Copy link
Owner

AttributeError: 'module' object has no attribute 'version'

It looks like this is not the latest psutil version. Try print(psutil.__version__).

@amjith
Copy link
Author

amjith commented Jan 30, 2015

Mystery solved.

I couldn't try print(psutil.__version) because psutil won't allow me to import it.

I ran a locate psutil and found this:

/Library/Python/2.7/site-packages/_psutil_osx.so
/Library/Python/2.7/site-packages/_psutil_posix.so

That is the system python that came with OS X and not the brew installed latest Python. I must have installed an old version of psutil using the old version Python and subsequently uninstalled it but those files were left behind after the uninstall. So when I installed the new version it kept referencing to this old .so files.

I removed them by hand and tried again and it works like a charm. Thank you!

>>> import psutil
>>> psutil.version_info
(2, 2, 0)
>>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants