ImportError with packages in site-packages.

71 views
Skip to first unread message

AlighaThor

unread,
Mar 29, 2018, 11:53:54 AM3/29/18
to web2py-users
Hi! I'm stuck importing packages within site-packages (the web2py one). I'm trying to import the Request library:



Ticket ID

127.0.0.1.2018-03-29.10-43-13.c356e4d3-44b6-4b74-a896-d0da7de9d0b1

<type 'exceptions.ImportError'> (ImportError("Cannot import module 'applications.myapp.modules.requests'",), <traceback object at 0x7f3830416440>)

Versión

web2py™Version 2.16.1-stable+timestamp.2017.11.13.23.50.07
PythonPython 2.7.12: /home/alighathor/Documentos/python-virtual-envs/web2py/bin/python2.7 (prefix: /home/alighathor/Documentos/python-virtual-envs/web2py)

Rastreo

1.
2.
3.
4.
5.
6.
7.
8.
9.
Traceback (most recent call last):
 
File "/home/alighathor/Documentos/Desarrollo/web2py/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
 
File "/home/alighathor/Documentos/Desarrollo/web2py/web2py/applications/myapp/controllers/default.py", line 7, in <module>
   
import requests
  File "/home/alighathor/Documentos/Desarrollo/web2py/web2py/gluon/custom_import.py", line 104, in custom_importer
    raise ImportError(e1, import_tb)  # there an import error in the module
ImportError: (ImportError("Cannot import module 'applications.myapp.modules.requests'",), <traceback object at 0x7f3830416440>)

I don't get why is telling me is trying to import from applications.myapp.modules.requests, when the package is not even there.

Thanks!



Leonel Câmara

unread,
Mar 29, 2018, 2:39:16 PM3/29/18
to web2py-users
The application's modules folder is the last place the importer looks that's why you get the error there. Have you restarted web2py after putting requests in the site-packages folder?

AlighaThor

unread,
Mar 29, 2018, 8:56:52 PM3/29/18
to web2py-users
Hi. Thanks for anwser. Well, I was trying to import "requests" in PythonAnywhere. I found that they have it pre-installed (I did'nt know). So, problem solved by now. I could'nt import the standalone request package inside site-packages or the app specific "modules" directory neither.

AlighaThor

unread,
Mar 29, 2018, 8:57:47 PM3/29/18
to web2py-users
And yes...I restarted the server several times without any effect. The same ImportError excepction.

Raul Monares

unread,
Apr 12, 2018, 12:45:10 PM4/12/18
to web2py-users
I have same problem. From command line the modules are imported correctly. Using python web2py.py also loads the modules. But nginx + uwsgi doesn't work. 

Hi Toni

unread,
Apr 19, 2018, 5:01:09 AM4/19/18
to web2py-users
I had the same issue.
Can you have a look at the installed packages:

python
>>> import pip
>>> pip.get_installed_distributions()

My requests module was installed at /home/myusername/.local -> but when I run web2py with nginx+uwsgi it is running with user "www-data".
I solved the problem by uninstalling requests and reinstalling it using sudo su:

sudo su
# pip install requests
Reply all
Reply to author
Forward
0 new messages