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

ERROR:root:Unhandled exception: No module named 'gevent.monkey' #2417

Closed
slrslr opened this issue Feb 8, 2020 · 17 comments
Closed

ERROR:root:Unhandled exception: No module named 'gevent.monkey' #2417

slrslr opened this issue Feb 8, 2020 · 17 comments

Comments

@slrslr
Copy link

@slrslr slrslr commented Feb 8, 2020

Step 1: Please describe your environment

  • ZeroNet version: 0.7.1
  • Operating system: Raspbian

Step 2: Describe the problem:

On Raspbian 10 with kernel 4.19.97-v7l+ i tried to "sudo apt update;sudo apt upgrade" and download https://github.com/HelloZeroNet/ZeroNet/archive/py3/ZeroNet-py3.tar.gz
Extract and install requirements:
Python 3.7.3, python3-pip is already the newest version (18.1-5+rpt1).

$ sudo python3 -m pip install -r requirements.txt
output is here (pass word is: a)

Launch: python3 zeronet.py --help

Startup error: Unable to switch gevent loop to libev: module 'gevent' has no attribute 'config'
ERROR:root:Unhandled exception: No module named 'gevent.monkey'
Traceback (most recent call last):
  File "zeronet.py", line 16, in main
    import main
  File "/home/me/dec/zeronet/src/main.py", line 22, in <module>
    import gevent.monkey
ModuleNotFoundError: No module named 'gevent.monkey'
Traceback (most recent call last):
  File "zeronet.py", line 16, in main
    import main
  File "/home/me/dec/zeronet/src/main.py", line 22, in <module>
    import gevent.monkey
ModuleNotFoundError: No module named 'gevent.monkey'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "zeronet.py", line 138, in <module>
    start()
  File "zeronet.py", line 134, in start
    main()
  File "zeronet.py", line 28, in main
    traceback.print_exc(file=open(error_log_path, "w"))
FileNotFoundError: [Errno 2] No such file or directory: './log/error.log'

$ sudo pip3 list|grep -i gevent

gevent            1.4.0
gevent-websocket  0.10.1

$ sudo apt list|grep -i monkey

graphmonkey/stable 1.7-4 all
libex-monkeypatched-perl/stable 0.03-1 all
libmonkey-patch-action-perl/stable 0.061-1 all
libmonkey-patch-perl/stable 0.03-2 all
libtwelvemonkeys-java-doc/stable 3.4.1-1 all
libtwelvemonkeys-java/stable 3.4.1-1 all
monkey/stable 0.9.3-1 armhf
monkeyrunner/stable 2.0.0-1 all
monkeysign-doc/stable 2.2.4 all
monkeysign/stable 2.2.4 all
monkeysphere/stable 0.43-3 all
monkeytail/stable 0.3.2-3 all
ruby-monkey-lib/stable 0.5.4-1 armhf
searchmonkey/stable 0.8.3-1 armhf
xul-ext-greasemonkey/stable 3.8-1 all
xul-ext-monkeysphere/stable 0.8-2 all

$ sudo apt list|grep -i gevent

python-gevent-dbg/stable 1.3.7-1 armhf
python-gevent-doc/stable 1.3.7-1 all
python-gevent-websocket/stable 0.9.3-1 all
python-gevent/stable,now 1.3.7-1 armhf [installed]
python3-gevent-dbg/stable 1.3.7-1 armhf
python3-gevent/stable 1.3.7-1 armhf
uwsgi-plugin-gevent-python3/stable 2.0.18-1 armhf
uwsgi-plugin-gevent-python/stable 2.0.18-1 armhf
@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 8, 2020

Please run this:

python3 -c "import gevent; print(gevent.__version__, gevent); print(dir(gevent))"
Example output:
1.4.0 <module 'gevent' from '/usr/local/lib/python3.6/dist-packages/gevent/__init__.py'> ['Greenlet', 'GreenletExit', 'Timeout', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__greenlet_primitives', '__hub_local', '__hub_primitives', '__ident', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '__waiter', '_compat', '_config', '_greenlet', '_greenlet_primitives', '_hub_local', '_hub_primitives', '_ident', '_interfaces', '_signal_class', '_signal_metaclass', '_signal_module', '_tblib', '_util', '_version_info', '_waiter', 'absolute_import', 'config', 'exceptions', 'fork', 'get_hub', 'getcurrent', 'getswitchinterval', 'greenlet', 'hub', 'idle', 'iwait', 'joinall', 'kill', 'killall', 'libev', 'namedtuple', 'os', 'reinit', 'setswitchinterval', 'signal', 'signal_handler', 'sleep', 'spawn', 'spawn_later', 'spawn_raw', 'timeout', 'version_info', 'wait', 'with_timeout']

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 8, 2020

@HelloZeroNet
output is:

Traceback (most recent call last):
File "", line 1, in
AttributeError: module 'gevent' has no attribute 'version'

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 8, 2020

Hm, then:
python3 -c "import gevent; print(gevent); print(dir(gevent))"
And check what's in that directory/file. I should be similar to this: https://github.com/gevent/gevent/blob/master/src/gevent/__init__.py

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 8, 2020

@HelloZeroNet
output is:

<module 'gevent' (namespace)>
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

the output does not look like a directory, so while you mention init.py, i tried:

$ locate init.py|grep -i gevent

/usr/lib/python2.7/dist-packages/gevent/__init__.py
/usr/lib/python2.7/dist-packages/gevent/__init__.pyc
/usr/lib/python2.7/dist-packages/gevent/_ffi/__init__.py
/usr/lib/python2.7/dist-packages/gevent/_ffi/__init__.pyc
/usr/lib/python2.7/dist-packages/gevent/libev/__init__.py
/usr/lib/python2.7/dist-packages/gevent/libev/__init__.pyc
/usr/lib/python2.7/dist-packages/gevent/libuv/__init__.py
/usr/lib/python2.7/dist-packages/gevent/libuv/__init__.pyc
/usr/lib/python2.7/dist-packages/gevent/resolver/__init__.py
/usr/lib/python2.7/dist-packages/gevent/resolver/__init__.pyc

but i am using "python3 zeronet.py" command.

there is a list of all paths to init.py

$ locate gevent.py
output is empty

do you have ideas on another commands to try?

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 8, 2020

you can check the actually loaded file using python3 -c "import gevent; print(gevent); print(gevent.__file__)"
and compare it with the path in
python3 -m pip show gevent

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 8, 2020

I found the cause of this whole issue. The error mentioned in the first post appear only when i run "python3 zeronet.py --help" as a non root user. When i run as root, it works OK.

Zeronet files has access rights of a non root user (under which i attempt to run zeronet)
Python binary /usr/bin/python3 has root access rights.

I found that i can allow any linux user to run python as root (maybe bad idea) like this:
sudo chmod u+s /usr/bin/python3

I am not sure if you can influence the error displayed so it suggest there is issue with access rights.
Or can the installation commands on readme.md include additional command to change permissions somehow so this issue can not happen?

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 9, 2020

If you execute python3 -m pip install --user gevent as an user, then it will install the packages to the user directory (~/.local), but adding read right to the directory shown with python3 -m pip show gevent command also should work.

I have never seen error like this, so it should be linux-dist specific.
For me on debian 10:

$ ls -ald /usr/local/lib/python3.7/dist-packages
drwxrwsr-x 21 root staff 4096 Feb  5 02:55 /usr/local/lib/python3.7/dist-packages

$ ls -ald /usr/local/lib/python3.7/dist-packages/gevent
drwxr-sr-x 9 root staff 4096 Feb  5 02:54 /usr/local/lib/python3.7/dist-packages/gevent

$ python3 -c "import gevent; print(gevent); print(gevent.__file__)"
<module 'gevent' from '/usr/local/lib/python3.7/dist-packages/gevent/__init__.py'>
/usr/local/lib/python3.7/dist-packages/gevent/__init__.py
@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 9, 2020

@HelloZeroNet here is update regarding this issue (only root/sudo can launch zeronet on Raspbian 10):

i see the same (correct) output/permissions regarding python packages as you, except:
"$ ls -ald /usr/local/lib/python3.7/dist-packages/gevent"
where it is:
drwx--S--- 9
you have:
drwxr-sr-x 9

adding read right to the directory shown with python3 -m pip show gevent command also should work.

/usr/local/lib/python3.7/dist-packages has:
Access: (2775/drwxrwsr-x) Uid: ( 0/ root) Gid: ( 50/ staff)
(which looks like to already have read permission)

execute "python3 -m pip install --user gevent" as an user, then it will install the packages to the user directory (~/.local)

so i tried "$ python3 -m pip uninstall gevent"
it removed:
/usr/local/lib/python3.7/dist-packages/gevent-1.4.0.dist-info/*
/usr/local/lib/python3.7/dist-packages/gevent/*
then i tried your command "$ sudo python3 -m pip install --user gevent" (without sudo it errored)
result: "Successfully installed gevent-1.4.0"
but "$ python3 zeronet.py" (ran as non-root) says: No module named 'gevent'

# sudo python3 -m pip show gevent
Location: /root/.local/lib/python3.7/site-packages

So not knowing the cause i uninstalled gevent and installed it again without --user switch.

What then worked (to prevent errors described in the first post of this ticket - running zeronet as non-root) is to SETUID /usr/bin/python:
$ sudo chmod u+s /usr/bin/python3
Now i can "$ python3 zeronet.py" without errors (mentioned in first post of this issue) but possibly this is security issue to SETUID python.

I am thinking if you can influence the error displayed when launching ZN without sudo (first post of this issue) so it suggest there is issue with access rights or can the installation commands on readme.md include additional command to change permissions somehow?

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 9, 2020

then i tried your command "$ sudo python3 -m pip install --user gevent" (without sudo it errored)

What error did it gave to you?

Executing with sudo won't work, because that way it will install to /root/.local/ directory that is not readable by the user.

For me:

$ python3 -m pip install gevent --ignore-installed --user
$ python3 -m pip show gevent
Name: gevent
Version: 1.4.0
Summary: Coroutine-based network library
Home-page: http://www.gevent.org/
Author: Denis Bilenko
Author-email: denis.bilenko@gmail.com
License: MIT
Location: /home/user/.local/lib/python3.6/site-packages
Requires: greenlet
Required-by: gevent-websocket
$ python3 -c "import gevent; print(gevent)"
<module 'gevent' from '/home/user/.local/lib/python3.6/site-packages/gevent/__init__.py'>

Alternatively you can copy the /root/.local/lib/python3.7/ directory to /home/youser/.local/lib/python3.7

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 9, 2020

@HelloZeroNet

What error did it gave to you?

$ python3 -m pip install gevent --user
and
$ python3 -m pip show gevent
both returns these kind of errors

Alternatively you can copy the /root/.local/lib/python3.7/ directory to /home/youser/.local/lib/python3.7

i tried this, but do not know how to do it

  1. login as a non root user
  2. cd /home/nonrootuser;sudo rsync -a /usr/local/lib/python3.7 ./.local/lib/;sudo chown -R $(whoami):$(whoami) ./.local/lib/
  3. find ./.local/lib/ -iname gevent -ls
  5922838      4 drwx--S---   2 nonrootuser      nonrootuser          4096 Feb  9 23:29 ./.local/lib/python3.7/dist-packages/gevent-1.4.0.dist-info
  5922841      4 drwx--S---   5 nonrootuser      nonrootuser          4096 Feb  8 13:49 ./.local/lib/python3.7/dist-packages/geventwebsocket
  5922840      4 drwx--S---   2 nonrootuser      nonrootuser          4096 Feb  8 13:49 ./.local/lib/python3.7/dist-packages/gevent_websocket-0.10.1.dist-info
  5922839      4 drwx--S---   9 nonrootuser      nonrootuser          4096 Feb  9 23:29 ./.local/lib/python3.7/dist-packages/gevent

$ python3 zeronet.py
$ python3 -m pip show gevent
continue showing errors mentioned in the first post and under link in this my post

so far what worked to run ZN as a not root and without sudo was SETUID (sudo chmod u+s /usr/bin/python3)

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 11, 2020

Yeah it won't work without having read access to /usr/local/lib/python3.7/dist-packages/*
So you need to execute sudo chmod -R a+r /usr/local/lib/python3.7/dist-packages/ that will add read access to everyone to all files in that directory

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 11, 2020

It assigned read permission to all users, but despite of that, zeronet launching continue to show gevent.monkey error (when launched as a non-root user and without sudo).
The "find" command complains about lack of permission:

$ find /usr/local/lib/python3.7/dist-packages/ -type f -ls

...
find: '/usr/local/lib/python3.7/dist-packages/geventwebsocket/websocket.py': Permission denied
find: '/usr/local/lib/python3.7/dist-packages/geventwebsocket/utf8validator.py': Permission denied
find: '/usr/local/lib/python3.7/dist-packages/websocket/cacert.pem': Permission denied
find: '/usr/local/lib/python3.7/dist-packages/websocket/_handshake.py': Permission denied
find: '/usr/local/lib/python3.7/dist-packages/websocket/_utils.py': Permission denied
...

$ sudo find /usr/local/lib/python3.7/dist-packages/ -type f -ls

...
  3411387     16 -rw-r--r--   1 root     staff       16046 Feb  8 13:49 /usr/local/lib/python3.7/dist-packages/geventwebsocket/websocket.py
  3411388     12 -rw-r--r--   1 root     staff       10060 Feb  8 13:49 /usr/local/lib/python3.7/dist-packages/geventwebsocket/utf8validator.py
  3411328    300 -rw-r--r--   1 root     staff      304893 Feb  8 13:49 /usr/local/lib/python3.7/dist-packages/websocket/cacert.pem
  3411339      8 -rw-r--r--   1 root     staff        6507 Feb  8 13:49 /usr/local/lib/python3.7/dist-packages/websocket/_handshake.py
  3411340      4 -rw-r--r--   1 root     staff        3824 Feb  8 13:49 /usr/local/lib/python3.7/dist-packages/websocket/_utils.py
...

$ $ stat /usr/local/lib/python3.7/dist-packages

  File: /usr/local/lib/python3.7/dist-packages
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 807h/2055d      Inode: 3219854     Links: 32
Access: (2775/drwxrwsr-x)  Uid: (    0/    root)   Gid: (   50/   staff)
@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 14, 2020

Please try this as an user:

$ python3 -m pip
/usr/bin/python3: No module named pip

$ wget https://bootstrap.pypa.io/get-pip.py

$ python3 get-pip.py --user
[..]
Successfully installed pip-20.0.2 setuptools-45.2.0 wheel-0.34.2

$ python3 -m pip install -r requirements.txt --user --ignore-installed
[..]
Successfully installed PySocks-1.7.1 asn1crypto-1.3.0 base58-2.0.0 cffi-1.14.0 coincurve-13.0.0 gevent-websocket-0.10.1 maxminddb-1.5.2 msgpack-0.6.2 pyasn1-0.4.8 pycparser-2.19 python-bitcoinlib-0.10.2 rsa-4.0 websocket-client-0.57.0

(optional) If you see distutils error when running python3 get-pip.py

$ python3 get-pip.py --user
[..]
ModuleNotFoundError: No module named 'distutils.util'

$ wget https://github.com/python/cpython/archive/3.7.tar.gz

$ tar xvpfz 3.7.tar.gz --strip 2 --wildcards cpython-*/Lib/distutils

$ python3 get-pip.py --user
[..]
Successfully installed pip-20.0.2 setuptools-45.2.0 wheel-0.34.2

$ export PYTHONPATH=~/.local/lib/python3.7/

$ mv distutils ~/.local/lib/python3.7/

$ python3 -m pip install -r requirements.txt --user --ignore-installed
[..]
Successfully installed PySocks-1.7.1 asn1crypto-1.3.0 base58-2.0.0 cffi-1.14.0 coincurve-13.0.0 gevent-websocket-0.10.1 maxminddb-1.5.2 msgpack-0.6.2 pyasn1-0.4.8 pycparser-2.19 python-bitcoinlib-0.10.2 rsa-4.0 websocket-client-0.57.0

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 21, 2020

$ python3 -m pip

Usage:
/usr/bin/python3 -m pip [options]

$ wget https://bootstrap.pypa.io/get-pip.py

'get-pip.py' saved [1807342/1807342]

$ python3 get-pip.py --user

output (with errors) (pass word is: zz)

$ python3 -m pip install -r requirements.txt --user --ignore-installed

output (with errors) (pass word is: zz)

error: ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/home/nonrootuser/.local/include/python3.7m'

$ sudo ls -l /home/nonrootuser/.local/include/python3.7m && sudo stat /home/nonrootuser/.local/include/python3.7m

total 4
drwx------ 2 root nonrootuser 4096 Feb 9 23:24 greenlet

File: /home/nonrootuser/.local/include/python3.7m
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 807h/2055d Inode: 5922849 Links: 3
Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 1001/ nonrootuser)
Access: 2020-02-09 23:24:28.881704431 +0100
Modify: 2020-02-09 23:24:28.881704431 +0100
Change: 2020-02-09 23:24:28.881704431 +0100
Birth: -

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 21, 2020

That directory should not be owned by root, try rename/remove it before pip install

@slrslr

This comment has been minimized.

Copy link
Author

@slrslr slrslr commented Feb 21, 2020

Permission denied: '/home/nonrootuser/.local/include/python3.7m'

I changed the rights to match the user who is executing the command:

drwx------ 3 nonrootuser nonrootuser 4096 Feb 9 23:24 python3.7m
drwx------ 2 nonrootuser nonrootuser 4096 Feb 9 23:24 greenlet
(it was root nonrootuser)

except the include parent directory:
drwx------ 3 root nonrootuser 4096 Feb 9 23:24 include

but it still errored, then i chown also include and then command NOT errored due to that directory, but instead: Permission denied: '/usr/local/lib/python3.7/dist-packages/websocket_client-0.57.0.dist-info/METADATA'
that file and parent folders has permission "root staff"

-rw-r--r-- 1 root staff 7485 Feb 8 13:49 /usr/local/lib/python3.7/dist-packages/websocket_client-0.57.0.dist-info/METADATA
-rw-r--r-- 1 root staff 7485 Feb 8 13:49 METADATA

but despite of that i am surprised to see zeronet start to work when launched as a non root user:

$ python3 zeronet.py --version

  • Starting ZeroNet...
  • Libsecpk256k1 loaded: CompiledLib in 0.112s
    ZeroNet 0.7.1 r4455

which is why this issue was created (ZN erroring when launched without sudo)... i do not know what fixed this and why this permission issue happened. If it was due to how python or its module was installed (prefixed by sudo or from su terminal). I think that Linux noob users do not know the consequences and it can be good to prevent this issue somehow. This is Raspbian 10.

@HelloZeroNet

This comment has been minimized.

Copy link
Owner

@HelloZeroNet HelloZeroNet commented Feb 22, 2020

I think there should be no difference between Debian or Raspbian on permission handling, so the standard installation method should work.

I have tried to install it on VMWare, but I was unable to reproduce the problem

@slrslr slrslr closed this Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.