Hi, I am running web2py Version 2.25.1-stable in virtualenv (python 3.9.5, it happens also in python 3.10.10)
After activating the virtualenv, I installed requests $ pip install request $ pip show requests Name: requests Version: 2.31.0 Summary: Python HTTP for Humans. Home-page: https://requests.readthedocs.io Author: Kenneth Reitz Author-email: m...@kennethreitz.org License: Apache 2.0 Location: /Users/z/dev/web2py/.direnv/python-3.9/lib/python3.9/site-packages Requires: certifi, charset-normalizer, idna, urllib3 Required-by: Importing requests from bpython gives no errors. Importing requests in myapp gives an error. I also tried with other external libraries, some of them do work, some others cannot be imported. About this case, I have tried the following: In "web2py/applications/myapp/models/0.py": # - - - - - - - - - - - - - - - # added the virtualenv path to sys.path site_package_path = "/Users/z/dev/web2py/.direnv/python-3.9/lib/python3.9/site-packages" if site_package_path not in sys.path: sys.path.append(site_package_path) try: import requests except: raise Exception('import error: "requests" not found') # - - - - - - - - - - - - - - - I am running web2py with: $python web2py.py -a 'pwd' Error log: # - - - - - - - - - - - - - - - Ticket ID 127.0.0.1.2023-10-24.05-48-51.a557dcfb-55a3-4063-ac27-879cad8fe799 <class 'Exception'> import error: "requests" not found Version web2py™ Version 2.25.1-stable+timestamp.2023.10.08.18.44.43 Python Python 3.9.5: /Users/z/dev/web2py/.direnv/python-3.9/bin/python (prefix: /Users/z/dev/web2py/.direnv/python-3.9) ... Traceback (most recent call last): File "/Users/z/dev/web2py/gluon/custom_import.py", line 78, in custom_importer result = sys.modules[modules_prefix] KeyError: 'applications.wh.modules.requests' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/z/dev/web2py/applications/wh/models/0.py", line 29, in <module> import requests File "/Users/z/dev/web2py/gluon/custom_import.py", line 80, in custom_importer raise ImportError("No module named %s" % modules_prefix) ImportError: No module named applications.wh.modules.requests During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/z/dev/web2py/gluon/restricted.py", line 219, in restricted exec(ccode, environment) File "/Users/z/dev/web2py/applications/wh/models/0.py", line 31, in <module> raise Exception('import error: "requests" not found') Exception: import error: "requests" not found Error snapshot help Exception(import error: "requests" not found) inspect attributes Exception instance attributes __cause__ None __class__ <class 'Exception'> __context__ ImportError('No module named applications.wh.modules.requests') __delattr__ <method-wrapper '__delattr__' of Exception object> __dict__ {} __dir__ <built-in method __dir__ of Exception object> __doc__ 'Common base class for all non-exit exceptions.' __eq__ <method-wrapper '__eq__' of Exception object> __format__ <built-in method __format__ of Exception object> __ge__ <method-wrapper '__ge__' of Exception object> __getattribute__ <method-wrapper '__getattribute__' of Exception object> __gt__ <method-wrapper '__gt__' of Exception object> __hash__ <method-wrapper '__hash__' of Exception object> __init__ <method-wrapper '__init__' of Exception object> __init_subclass__ <built-in method __init_subclass__ of type object> __le__ <method-wrapper '__le__' of Exception object> __lt__ <method-wrapper '__lt__' of Exception object> __ne__ <method-wrapper '__ne__' of Exception object> __new__ <built-in method __new__ of type object> __reduce__ <built-in method __reduce__ of Exception object> __reduce_ex__ <built-in method __reduce_ex__ of Exception object> __repr__ <method-wrapper '__repr__' of Exception object> __setattr__ <method-wrapper '__setattr__' of Exception object> __setstate__ <built-in method __setstate__ of Exception object> __sizeof__ <built-in method __sizeof__ of Exception object> __str__ <method-wrapper '__str__' of Exception object> __subclasshook__ <built-in method __subclasshook__ of type object> __suppress_context__ False __traceback__ <traceback object> args ('import error: "requests" not found',) with_traceback <built-in method with_traceback of Exception object> Frames File /Users/z/dev/web2py/gluon/restricted.py in restricted at line 219 code arguments variables File /Users/z/dev/web2py/applications/wh/models/0.py in <module> at line 31 code arguments variables Function argument list () Context locals ... <function embed64> iteritems : <function <lambda>> local_import : <function build_environment.<locals>.<lambda>> myconf : {'app': {'name': 'WH', 'author': 'Your Name <you...ormstyle': 'bootstrap3_inline', 'separator': ''}} redirect : <function redirect> reduce : <built-in function reduce> request : <Storage {'env': <Storage {'SERVER_SOFTWARE': 'R...050b77f0>, '_custom_import_track_changes': True}> response : <Storage {'status': 200, 'headers': {'X-Powered-...ndex/\\w+\\.py$'], 'view': 'default/index.html'}> session : <Storage {}> site_package_path : "'/Users/z/dev/web2py/.direnv/python-3.9/lib/python3.9/site-packages'" sys : <module 'sys' (built-in)> to_bytes : <function to_bytes> to_native : <function to_native> track_changes : <function track_changes> xmlescape : <function xmlescape> xrange : <class 'range'> session response body : <_io.StringIO object at 0x10509de50> cookies : session_id_wh : 127.0.0.1-3599de20-98fe-4a6f-a572-aa7d12f28231 comment : domain : expires : httponly : max-age : path : / samesite : secure : version : delimiters : {{ }} files : flash : form_label_separator : : formstyle : table3cols generic_patterns : * headers : X-Powered-By : web2py menu : meta : models_to_run : ^\w+\.py$ ^default/\w+\.py$ ^default/index/\w+\.py$ postprocessing : session_client : 127.0.0.1 session_cookie_compression_level : None session_cookie_expires : None session_data_name : session_data_wh session_file : None session_filename : /Users/z/dev/web2py/applications/wh/sessions/127.0.0.1-3599de20-98fe-4a6f-a572-aa7d12f28231 session_hash : af8c96c5e9a768088deb3555c108286d session_id : 127.0.0.1-3599de20-98fe-4a6f-a572-aa7d12f28231 session_id_name : session_id_wh session_masterapp : wh session_new : True session_storage_type : file status : 200 view : default/index.html In file: /Users/z/dev/web2py/applications/wh/models/0.py 1. <code object <module> at 0x103f03a80, file "/Users/z/dev/web2py/applications/wh/models/0.py", line 1> # - - - - - - - - - - - - - - - Any hints? Thank you -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/CAKC%3DaX7J%3DVwWXCtX8EfNahCvdft0tktds-0wZCqd0uKTDWrYjw%40mail.gmail.com.