I am trying to get a web2py application running and I have the following code in one of the controllers.
file name : default.py
import requests
def index():
...
In my currently activated virtualenv, I have installed requests using pip, as you can see below.
(web2pyenv) PS C:\Users\rajesh\Desktop\code\RealPython-Part2\web2py> pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in c:\users\rajesh\desktop\code\realpython-part2\web2py\web2pyenv\lib\site-packages
Cleaning up...
If I open up a python shell, I can import requests and do the usual stuff.
(web2pyenv) PS C:\Users\rajesh\Desktop\code\RealPython-Part2\web2py> python
Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://google.com").status_code
200
>>>
When I try accessing my web2py application, it still throws the following error.
Traceback (most recent call last):
File "gluon/restricted.py", line 224, in restricted
File "C:/Users/rajesh/Desktop/code/RealPython-Part2/web2py/start/applications/pulse/controllers/default.py", line 1, in <module>
import requests
File "gluon/custom_import.py", line 86, in custom_importer
ImportError: Cannot import module 'requests'
Any pointers on what I am doing wrong here?
Most likely you are using the Windows binary version of web2py. This version includes its own Python interpreter, so it doesn't use the Python version you have installed on your machine (or any of its libraries). As long as you have Python installed, you are better off running the source code version of web2py. Running from source, you will be able to import any installed modules.
Related
I have installed python 2.7 and also I have requests package installed. I am not sure of the reason, the site-packages are in a different location and my python 2.7 core files are in a different location
C:\Program Files\Python27
C:\Users\MyID\AppData\Roaming\Python\Python27\site-packages
I can see requests and the binaries in the path C:\Users\MyID\AppData\Roaming\Python\Python27\site-packages\requests. Yet when my job runs, it throws an error as shown below.
File "C:\Program Files (x86)\Jenkins\workspace\code\xxxx.py", line 36, in <module>
import requests
ImportError: No module named requests
I have only one version of python installed.
C:\Users\MyID\Desktop\xxx\Automation\xxxxxx\venv\Scripts>python
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
This is most probably the problem of virtual environment, virtual environment (venv) isolate your work environment in such a way that you can have different workspace for same version of python, that's why you are getting the error, I suspect that you installed request module in original python, but trying to run the script in virtual environment, hence it's giving error
Here, try these steps and tell the result
Open CMD
Write cd C:\Users\MyID\Desktop\xxx\Automation\xxxxxx\venv\Scripts , Press enter.
Write python -m pip install requests
Wait for it and tell the result, this must fix your problem
For reference on virtual environment and pip, look at this.
When importing requests in python3, I'm getting the following error:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32
bit (Intel)] on win32 Type "help", "copyright", "credits" or
"license" for more information
>>>> import requests
Traceback (most recent call last): File "<stdin>", line 1, in <module> File
"C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests-2.19.1-py3.7.egg\requests\__init__.py", line 44, in <module>
import chardet
ModuleNotFoundError: No module named 'chardet'
This is a fresh install, but because of the env I'm working in, I couldn't use pip to install requests. I had to download the source and install via the setup.py install file.
Doing some searches yields some results, but nothing that seems to be a solution for my situation.
Thanks
It is a dependency and is missing from you site-packages. Since you said you can't use pip you have to install the dependencies manually.
requires = [
'chardet>=3.0.2,<3.1.0',
'idna>=2.5,<2.8',
'urllib3>=1.21.1,<1.24',
'certifi>=2017.4.17'
]
this is what requests setup files mentioned as requirements for requests. Try installing all of these and try again.
hope this helps!
Try installing chardet module using this command:
pip3 install chardet
I'm trying to use pyttsx on Ubuntu Linux (64 bit, PC) with Python 2.7. I've successfully used pip to install the package
$sudo -H pip install pyttsx
$pip list
...
pyttsx (1.1)
...
When I try to import it the import call fails
$ python
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pyttsx
I'm not sure why I'm getting this. When I search for the question here on Stack Overflow I encounter one other instance about the same error message on a Raspberry Pi. But the solution mentioned there doesn't bring resolution on my PC so I don't think it is not related.
Any ideal what I am missing that is preventing the import from being successful?
Make sure your pip is tied to your python installation by checking both path's.
In Pip check:
`pip --version`
pip 9.0.1 from C:\Python27\lib\site-packages (python 2.7)
Later in python:
import sys
print sys.executable
C:\Python27\python.exe
run which pip, which python, make sure they are same suite
when run pip install, it should feedback the package is installed in which path
run this code in python
import sys
for i in sys.path:
print i
to check if your syspath including that path or not.
I've used MSYS2 to install the MinGW-W64 version of Python 3.6 (mingw-w64-x86_64-python3). Upon importing ssl, an ImportError is raised:
$ python3
Python 3.6.2 (default, Aug 15 2017, 10:59:43) [GCC 7.1.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "G:/msys64/mingw64/lib/python3.6\ssl.py", line 101, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified procedure could not be found.
>>>
I'm not sure why this. pacman shows both mingw-w64-x86_64-openssl and openssl as installed. /mingw64/lib/python3.6/lib-dynload/_ssl-cpython-36m.dll exists. Other .dll files from the same directory (like those used for the json and sqlite3 modules) import fine.
To make matters weirder, the Python 2 version (mingw-w64-x86_64-python2) doesn't have this problem.
This is not a correct solution (the MSYS2 folks are working on the real solution), but as a temporary workaround for anyone else who gets stuck on this:
After installing mingw-w64-x86_64-python3 copy
C:\msys64\mingw64\bin\LIBEAY32.dll and
C:\msys64\mingw64\bin\SSLEAY32.dll
to
C:\msys64\mingw64\lib\python3.6\lib-dynload\LIBEAY32.dll and
C:\msys64\mingw64\lib\python3.6\lib-dynload\SSLEAY32.dll respectively.
Afterwards import ssl (and tools that rely on it, like pip3) should work correctly.
For some reason I'm getting this error when trying to import gevent inside my docker container:
# python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/gevent/__init__.py", line 51, in <module>
from gevent.hub import get_hub, iwait, wait
File "/usr/local/lib/python2.7/dist-packages/gevent/hub.py", line 31, in <module>
from gevent._util import _NONE
ImportError: cannot import name _NONE
>>>
Which is odd because _util.py exists, it's in the dist-packages/gevent directory. When I did a pip install on another system, it works fine.
Anyone have any ideas what might be going on?
Have you upgraded gevent package recently or maybe installed it over old version?
I ran pip install --ignore-installed gevent to update old version of this package in my virtualenv, and then this error starts to appear.
I fixed it with pip uninstall gevent (two times to completely remove it) followed by pip install gevent.
I think you import gevnet this module is not you see it.
you can print something in you _util.py module.
if nothing print, I guess "/usr/local/lib/python2.7/dist-packages/gevent/hub.py" import _util is not in /usr/local/lib/python2.7/dist-packages/gevnet, and you can try to print sys.path to find real import path and fix it.
In my Method:
uninstall gevent.
use a another system gevnet or virtualenv package,and copy to you real(I guess you have a env path like '/usr/local/lib64')
exec python -c 'import gevent' test is ok.