See below. In both tests the requests library is in the last element of the 
path.

TEST1, plain python shell - import OK

(test) tclerckx@stark:~/temp/test$ python
Python 3.10.6 (main, Jan 14 2023, 23:48:13) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__file__
'/home/tclerckx/.pyenv/versions/test/lib/python3.10/site-packages/requests/__init__.py'
>>> import sys
>>> sys.path
['', '/home/tclerckx/.pyenv/versions/3.10.6/lib/python310.zip', 
'/home/tclerckx/.pyenv/versions/3.10.6/lib/python3.10', 
'/home/tclerckx/.pyenv/versions/3.10.6/lib/python3.10/lib-dynload', 
'/home/tclerckx/.pyenv/versions/test/lib/python3.10/site-packages']
>>> 

TEST2, python web2py shell - import FAILS

(test) tclerckx@stark:~/temp/test/web2py$ python web2py.py -S welcome -M 
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2023
Version 2.24.1-stable+timestamp.2023.03.23.05.07.17
Database drivers available: sqlite3, imaplib, pymysql
WARNING:web2py:import IPython error; use default python shell
Python 3.10.6 (main, Jan 14 2023, 23:48:13) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import requests
Traceback (most recent call last):
  File "/home/tclerckx/temp/test/web2py/gluon/custom_import.py", line 78, 
in custom_importer
    result = sys.modules[modules_prefix]
KeyError: 'applications.welcome.modules.requests'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/tclerckx/temp/test/web2py/gluon/custom_import.py", line 80, 
in custom_importer
    raise ImportError("No module named %s" % modules_prefix)
ImportError: No module named applications.welcome.modules.requests
>>> import sys
>>> sys.path
['', '/home/tclerckx/temp/test/web2py/site-packages', 
'/home/tclerckx/temp/test/web2py', 
'/home/tclerckx/temp/test/web2py/gluon/packages/yatl', 
'/home/tclerckx/temp/test/web2py/gluon/packages/dal', 
'/home/tclerckx/.pyenv/versions/3.10.6/lib/python310.zip', 
'/home/tclerckx/.pyenv/versions/3.10.6/lib/python3.10', 
'/home/tclerckx/.pyenv/versions/3.10.6/lib/python3.10/lib-dynload', 
'/home/tclerckx/.pyenv/versions/test/lib/python3.10/site-packages']
>>> 

On Saturday, May 27, 2023 at 12:11:19 PM UTC+2 Massimiliano wrote:

> Maybe one thing you can do is to launch web2py shell and check paths.
>
> ./web2py.py -S <your-app-name> 
>
> import sys
> print(sys.path)
>
>
>
>
> Il giorno ven 26 mag 2023 alle ore 16:02 vald...@gmail.com <
> vald...@gmail.com> ha scritto:
>
>> <https://stackoverflow.com/posts/76341290/timeline>
>>
>> Asked this one on SO here 
>> <https://stackoverflow.com/questions/76341290/unable-to-import-requests-in-web2py-even-though-requests-is-accessible-directl>
>>  
>> as I was just reminded of how much nicer this community tends to be to newb 
>> questions.
>>
>> I'm attempting to integrate MSAL which requires the requests module.
>>
>> I'm running python 3.7 on Linux and using pipenv to manage the 
>> environment. I'm also using web2py 2.24.1 from source (as in I download the 
>> web2py framework via the source button on the web2py website).
>>
>> When I am in pipenv shell and go into the python shell, I can access the 
>> requests, however when I try to access it from web2py (running in same 
>> shell), I get the "module not found" error.
>>
>> When I check the site-packages folder the requests packages is present. I 
>> have checked the pythonpath and seen that the path from the virtual 
>> environment is present.
>>
>> When attempting to load the web2py python shell, it gives the same error.
>>
>> I'm probably missing something, but it sometimes appears as if web2py 
>> does some code compilation and then uses the compiled stuff and ignores 
>> code changes after a certain point. Asking as I have commented out all the 
>> code involving the requests module in an effort to get the web2py shell 
>> working, but still get the error and now the entire app is not working even 
>> on the master branch which was previously working.
>>
>> Not sure what to try next. Any ideas are appreciated.
>>
>> -- 
>> 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+un...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/83b8a4ab-120a-4106-83f2-d37652c23093n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/web2py/83b8a4ab-120a-4106-83f2-d37652c23093n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Massimiliano
>

-- 
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/9e3df18e-403a-4bd2-b42b-8c9028da601fn%40googlegroups.com.

Reply via email to