notebook
notebook copied to clipboard
AttributeError: module 'resource' has no attribute 'getpagesize'
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
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.
Hi @kevin-bates I also tried to run jupyter notebook through the windows command prompt. But the same issue I'm getting as follows:

System: Windows 10 x64 Python 3.7.8 [MSC v.1916 64 bit (AMD64)] on win32 pip: 20.1.1 notebook: 6.1.5
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).
Can you please elaborate on the solution??
我也遇到了这个问题。
解决方法有二: 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这个库,导致代码的运行出现问题。
您好,邮件已经收到。祝您工作顺利,生活愉快。
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.
您好,邮件已经收到。祝您工作顺利,生活愉快。
我也遇到同样的问题了,不过我的来由不一样。 我原本是WIndows+3.9.13的环境,可以跑jupyter。 现在创建了venv,重新安装jupyter,用Pycharm professional试图启动notebook,报了这个错误
您好,邮件已经收到。祝您工作顺利,生活愉快。
老哥你的邮箱自动回复哈哈哈
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.
您好,邮件已经收到。祝您工作顺利,生活愉快。
检查你的项目中是否有和 resource 同名的文件夹,尝试重命名
您好,邮件已经收到。祝您工作顺利,生活愉快。