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

AttributeError: module 'resource' has no attribute 'getpagesize' #5817

Open
lonelygoatherd opened this issue Oct 18, 2020 · 15 comments
Open

Comments

@lonelygoatherd
Copy link

Hi, when i tried to start jupyter notebook, an error occurred as below. AttributeError: module 'resource' has no attribute 'getpagesize'. I have reinstalled resource module but not work. I installed ipykernel module before, is it related ? Because i work well before that.
Wnidows, python3.7

@kevin-bates
Copy link
Member

Please provide more information, like the context in which you're seeing this. Is this message displayed in the notebook itself, or on the console of the notebook server, etc? A complete traceback is always helpful.

This SO hit also leads me to ask if you happen to have a local module named 'resource' that may be interfering with a module notebook/ipykernel needs, but can't really make that determination without helpful details.

@parthbs
Copy link

parthbs commented Nov 10, 2020

Hi @kevin-bates
I also tried to run jupyter notebook through the windows command prompt. But the same issue I'm getting as follows:

Screenshot 2020-11-10 200910

System: Windows 10 x64
Python 3.7.8 [MSC v.1916 64 bit (AMD64)] on win32
pip: 20.1.1
notebook: 6.1.5

@kevin-bates
Copy link
Member

Seems like that SO hit (above) is still the best bet. Please check your PYTHONPATH for a resource module that isn't the expected module (that supports getpagesize).

@ishkabir1401
Copy link

Can you please elaborate on the solution??

@FrankyTang
Copy link

我也遇到了这个问题。

解决方法有二:
1,卸载resource
2, 注释process_collector.py和notebookapp.py中涉及到resouce的代码,结果如下:
process_collector.py
#try:

import resource

print(resource)

_PAGESIZE = resource.getpagesize()

#except ImportError:
# Not Unix

_PAGESIZE = 4096

_PAGESIZE = 4096

notebookapp.py
#try:

import resource

#except ImportError:
# Windows

resource = None

resource = None

经过研究发现,这个问题归根到底是resouce 的问题。在python中,只有unix会有resource,而window下是没有的。但是不知道window下什么时候安装了resouce这个库,导致代码的运行出现问题。

@lonelygoatherd
Copy link
Author

lonelygoatherd commented Jan 18, 2022 via email

@danzimmerman
Copy link

Would it be possible to make this more nuanced than testing on ImportError on Windows?

If I try to use Jupyter with a ROS2 installation on Windows (using Robostack in a Conda environment) where I've built packages in a colcon workspace I get this error.

It appears that this is because Python ROS2 package provides a folder (I think for ament_index ) that gets interpreted as a Python package and gets loaded:

(humble) C:\Code\ros2\humble_ws>jupyter notebook
Traceback (most recent call last):
  File "C:\Users\<user>\mambaforge\envs\humble\Scripts\jupyter-notebook-script.py", line 5, in <module>
    from notebook.notebookapp import main
  File "C:\Users\<user>\mambaforge\envs\humble\Lib\site-packages\notebook\notebookapp.py", line 75, in <module>
    from .base.handlers import Template404, RedirectWithParams
  File "C:\Users\<user>\mambaforge\envs\humble\Lib\site-packages\notebook\base\handlers.py", line 24, in <module>
    import prometheus_client
  File "C:\Users\<user>\mambaforge\envs\humble\Lib\site-packages\prometheus_client\__init__.py", line 3, in <module>
    from . import (
  File "C:\Users\<user>\mambaforge\envs\humble\Lib\site-packages\prometheus_client\process_collector.py", line 10, in <module>
    _PAGESIZE = resource.getpagesize()
AttributeError: module 'resource' has no attribute 'getpagesize'

Inspecting in a Python terminal:

(humble) C:\Code\ros2\humble_ws>python
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import resource
>>> dir(resource)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>> resource.__path__
_NamespacePath(['C:\\Code\\ros2\\humble_ws\\build\\my_python_ros2_package\\resource'])

It appears that the resource module with .getpagesize() is never expected on Windows, and here it does NOT appear that there's any kind of conflict between the ROS2 packages and the resource module that actually exists on Linux. I can have an active colcon workspace on my $PATH on Linux and the resource import error does not happen.

@lonelygoatherd
Copy link
Author

lonelygoatherd commented Jul 30, 2022 via email

@2catycm
Copy link

2catycm commented Nov 6, 2022

我也遇到同样的问题了,不过我的来由不一样。
我原本是WIndows+3.9.13的环境,可以跑jupyter。
现在创建了venv,重新安装jupyter,用Pycharm professional试图启动notebook,报了这个错误

@lonelygoatherd
Copy link
Author

lonelygoatherd commented Nov 6, 2022 via email

@2catycm
Copy link

2catycm commented Nov 6, 2022

老哥你的邮箱自动回复哈哈哈

@ili3p
Copy link

ili3p commented Mar 24, 2023

My problem was mamba installed graalvm's python for some reason, and that version of python does not have resource.getpagesize. Using conda and their version of python solves the issue for me.

@lonelygoatherd
Copy link
Author

lonelygoatherd commented Mar 24, 2023 via email

@RoiexLee
Copy link

RoiexLee commented Jul 5, 2023

检查你的项目中是否有和 resource 同名的文件夹,尝试重命名

@lonelygoatherd
Copy link
Author

lonelygoatherd commented Jul 5, 2023 via email

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

No branches or pull requests

9 participants