Any idea what package I am missing.
Python:
#!/usr/bin/env python
import requests
import requests_cache
Error:
/bin/requests_cache/backends/init.py", line 54, in create_backend
_backend_dependencies[backend_name])
ImportError: You must install the python package: sqlite3
I have included the packages certfil, chardet, idna, requests, requests_cache and urllib3 in the execute directory..
I have it working on a python deployment with the following:
pip list
Package Version
-------------- ---------
certifi 2018.4.16
chardet 3.0.4
idna 2.6
pip 10.0.1
pysqlite 2.7.0
requests 2.18.4
requests-cache 0.4.13
urllib3 1.22
I know it says sqlite3 which I have tried including locally but this does not work.
sqlite3 is part of the standard library, but there are some environments where it isn't supported, for example cloud providers that use ephemeral storage. One that I'm aware of is Heroku: https://devcenter.heroku.com/articles/sqlite3
If that's the case for your environment, consider using one of the other backends instead: https://requests-cache.readthedocs.io/en/stable/user_guide/backends.html
Current versions of requests-cache will fall back to a non-persistent in-memory cache if sqlite3 isn't available.
Related
I am using gcalcli 4.3.0
https://github.com/insanum/gcalcli
using this docker image:
https://hub.docker.com/r/devopstestlab/gcalcli
I would like to use Fiddler (a HTTP(s) Proxy), to see what gcalcli sends/receives to/from Google.
By their documentation it states, that I can use environment variables for setting up a proxy:
http_proxy
https_proxy
proxy-username or proxy_username
proxy-password or proxy_password
But this doesn't work at all.
The proxy settings are not considered and just uses the regular connection route.
(No proxy error or similiar)
Using the command (all inside the docker container)
python -m pip install --upgrade pip
with the environment proxy settings, respects these values and works just as expected.
pip list output:
Package Version
------------------------ ---------
cachetools 5.0.0
certifi 2021.10.8
charset-normalizer 2.0.12
gcalcli 4.3.0
google-api-core 2.5.0
google-api-python-client 2.39.0
google-auth 2.6.0
google-auth-httplib2 0.1.0
googleapis-common-protos 1.55.0
httplib2 0.20.4
idna 3.3
oauth2client 4.1.3
parsedatetime 2.6
pip 19.3.1
protobuf 4.0.0rc2
pyasn1 0.4.8
pyasn1-modules 0.2.8
pyparsing 3.0.7
python-dateutil 2.8.2
requests 2.27.1
rsa 4.8
setuptools 41.6.0
six 1.16.0
uritemplate 4.1.1
urllib3 1.26.8
vobject 0.9.6.1
wheel 0.33.6
pip upgrade (all packages) seems to have no effect.
Since I have no clue about Python and Co., these are my researches which do not offer a solution:
Can't connect to google directory-api using proxy with httplib
https://code.google.com/archive/p/httplib2/issues/38
httplib2.ServerNotFoundError: Unable to find the server at accounts.google.com
https://groups.google.com/g/google-api-python-client/c/tXd-xd5rEqg
https://groups.google.com/g/httplib2-commit/c/t77mjFQOdVE
Google API + proxy + httplib2
Setting HTTP-proxy for Google Analytics Reporting API
Python3 BigQuery or Google Cloud Python through HTTP Proxy
The docker image is using Python 3.8.0
Any way or instruction to make the HTTPS_PROXY/https_proxy environment variables work?
Thank you for the answers.
I've seen several answers to this question, albeit none of the solutions have worked for my particular situation. I'm trying to get started building an API with Flask. When I try to import Flask-RESTful, I get an error in VS Code. For context, I am using Windows 11. Here are the first two lines of my .py file:
from flask import Flask
from flask_restful import Resource, Api, reqparse
The error I get reads as:
Import "flask_restful" could not be resolved Pylance(reportMissingImports)
Now, to add more context, I've checked to make sure the interpreter path is set using Ctrl+Shift+P to open the Command Palette and selecting the correct (and the only) Python interpreter for the project inside my virtual environment. When I run pip list, I get this output:
(api) C:\Users\<Username>\OneDrive\Documents\PythonProjects\api>pip list
Package Version
----------------------- ---------
aiohttp 3.8.1
aiosignal 1.2.0
alembic 1.8.0
aniso8601 9.0.1
anyio 3.6.1
async-timeout 4.0.2
attrs 21.4.0
bleach 5.0.1
certifi 2022.6.15
charset-normalizer 2.1.0
click 8.1.3
click-log 0.4.0
colorama 0.4.5
deprecation 2.1.0
docutils 0.19
dotty-dict 1.3.0
Flask 2.1.2
Flask-Migrate 3.1.0
Flask-RESTful 0.3.9
Flask-SQLAlchemy 2.5.1
flask-swagger 0.2.14
frozenlist 1.3.0
gitdb 4.0.9
GitPython 3.1.27
gotrue 0.5.0
greenlet 1.1.2
h11 0.12.0
httpcore 0.14.7
httpx 0.21.3
idna 3.3
importlib-metadata 4.12.0
invoke 1.7.1
itsdangerous 2.1.2
Jinja2 3.1.2
keyring 23.6.0
Mako 1.2.1
MarkupSafe 2.1.1
multidict 6.0.2
packaging 21.3
pip 22.0.4
pkginfo 1.8.3
postgrest-py 0.10.2
psycopg2 2.9.3
pydantic 1.9.1
Pygments 2.12.0
pyparsing 3.0.9
python-dateutil 2.8.2
python-gitlab 3.6.0
python-semantic-release 7.28.1
pytz 2022.1
pywin32-ctypes 0.2.0
PyYAML 6.0
readme-renderer 35.0
realtime 0.0.4
requests 2.28.1
requests-toolbelt 0.9.1
rfc3986 1.5.0
semver 2.13.0
setuptools 58.1.0
setuptools-scm 7.0.4
six 1.16.0
smmap 5.0.0
sniffio 1.2.0
SQLAlchemy 1.4.39
storage3 0.3.4
supabase 0.5.8
supabase-client 0.2.4
tomli 2.0.1
tomlkit 0.10.2
tqdm 4.64.0
twine 3.8.0
typing_extensions 4.3.0
urllib3 1.26.10
webencodings 0.5.1
websockets 9.1
Werkzeug 2.1.2
wheel 0.37.1
yarl 1.7.2
zipp 3.8.0
Why would the flask...Flask import work, but not flask_restful? I can see both in the Lib\site-packages folder in my project directory and the output from pip list outside the virtual environment is different, which signals to me that there isn't an issue with the path or directories.
EDIT: I forgot to mention that when I run the code using Ctrl + Alt + N, I get this output:
Traceback (most recent call last):
File "c:\Users\<Username>\OneDrive\Documents\PythonProjects\api\api.py", line 3, in <module>
from flask_restful import Resource, Api, reqparse
ModuleNotFoundError: No module named 'flask_restful'
Again, no errors with importing flask, only with flask_restful.
Any help with this will be greatly appreciated! Thank you in advance for your time. I'm happy to provide more info if needed. Thanks.
EDIT: I have updated pip and attempted to simply run the program inside the command prompt. This is what I got. I'm still getting the import error inside VS Code, though. I am going to see if using a different version of Python makes a difference. Thanks everyone for all of your help so far, I appreciate it!
EDIT: Okay, it seems like the issue is a little closer to being solved. So, I updated pip. I retried setting the interpreter path and, which some of you mentioned, it turns out that I'd been doing it wrong. I had to do Ctrl + Shift + P >> Python: Select Interpreter >> Enter interpreter path and select the correct path that way. I did this by going into the project directory, going to the scripts folder, and selecting python.exe.
That solved the issue with Pylance. I no longer see an error in the editor when working on the project. However, the interpreter will not show in the bottom right hand corner of the window. That may just be a bug and I can either look through the issues on GitHub or open a new one some other time I assume.
When I run the code with Ctrl + Alt + N I get a ModuleNotFoundError relating to flask_restful again. But, when I run set flask_app=api.py >> flask run in the terminal, it has changed from a white background in the browser to a black background and displays the message it is intended to display (a simple "Hello, World" as a test).
Should I just keep going until I run into another issue? I also tried python -m api and that worked as well. Should I just ignore the VS Code output window? Also, sorry about the late replies. I appreciate everyone's help and patience.
Use the Ctrl+Shift+P command, search for and select Python:Select Interpreter(Or click directly on the python version displayed in the lower right corner), and select the correct interpreter.
I wanted to deploy my app engine to use machine learning engine in Gcloud with the following code:
https://github.com/novinfard/temp
I encountered a strange error as follows:
ImportError: No module named oauth2client.client
However this library have already installed in app engine, as the following upgrade command return that everything is updated:
sudo pip install --upgrade google-api-python-client
I applied the 'vendor' solutions as described here as well:
https://stackoverflow.com/a/44011777/3477974
But this does not work either.
How this problem can be solved?
As of version 1.7.0 of google-api-python-client the hard requirement for oauth2client has been dropped. I.e. it will not be included when installing the google-api-python-client.
You can fix this by manually installing oauth2client in your vendor folder.
$ pip install -t <vendor_folder> oauth2client
This release drops the hard requirement on oauth2client and installs
google-auth by default instead. oauth2client is still supported but will
need to be explicitly installed.
https://github.com/google/google-api-python-client/releases/tag/v1.7.0
I've run into the issue that when I import the requests module in iPython it works great however when I try to compile a file that uses it everything goes bananas. Similarly when I try to import requests in the standard python interpreter things go bananas as well.
Any ideas?
import csv, requests, re
Leads to
Traceback (most recent call last):
File "sherpa_romeo.py", line 18, in <module>
import csv, requests, re
ImportError: No module named requests
I'm thinking that I may have pip'd to the wrong version of python.
I installed with the command:
pip install requests
I ran the command pip list and it returned:
certifi (14.05.14)
Flask (0.10.1)
gnureadline (6.3.3)
ipython (2.4.1)
itsdangerous (0.24)
Jinja2 (2.7.3)
MarkupSafe (0.23)
oauthlib (0.6.3)
pip (1.5.6)
pokitdok (0.9)
requests (2.4.0)
requests-oauthlib (0.4.1)
sendgrid (1.1.0)
setuptools (5.4.2)
smtpapi (0.1.2)
unittest2 (0.5.1)
virtualenv (1.11.6)
Werkzeug (0.9.6)
wsgiref (0.1.2)
which includes requests so I'm confused on why it's not working.
In the directory where you have the file that you compile, see if there is another file named "requests" and rename it
I'm trying to get the Python libraries for Reddit installed on my Mac. I want to run them using PyCharm for development as I like it as a Python IDE.
I'm running the Cassandra, Memcached, RabbitMQ, and Postgres servers inside a Virtual Box instance that is accessible via the Virtual Box Host-only adapter. This is working as I can start Reddit in the Virtual Box and access it from my Mac just fine.
When running the paster script to see if the Reddit Python source install is working on the Mac. I get the following error:
Traceback (most recent call last):
File "/Users/inflector/software/new-day/reddit/dev/bin/paster", line 8, in <module>
load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')()
File "/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages/paste/script/command.py", line 93, in run
commands = get_commands()
File "/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages/paste/script/command.py", line 135, in get_commands
plugins = pluginlib.resolve_plugins(plugins)
File "/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages/paste/script/pluginlib.py", line 82, in resolve_plugins
pkg_resources.require(plugin)
File "build/bdist.linux-i686/egg/pkg_resources.py", line 666, in require
File "build/bdist.linux-i686/egg/pkg_resources.py", line 569, in resolve
pkg_resources.VersionConflict: (WebOb 1.2.3 (/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages), Requirement.parse('webob==1.0.8'))
If I downgrade the installation to WebOb 1.0.8, I get the reverse, it wants 'WebOb>=1.2'.
'pip list' shows these packages installed:
amqplib (1.0.2)
Babel (0.9.6)
bcrypt (1.0.2)
Beaker (1.6.4)
BeautifulSoup (3.2.1)
beautifulsoup4 (4.2.1)
boto (2.9.5)
cffi (0.6)
chardet (2.1.1)
crypto (1.1.0)
cssutils (0.9.5.1)
Cython (0.19.1)
decorator (3.4.0)
FormEncode (1.2.6)
kazoo (1.1)
l2cs (2.0.2)
lxml (3.2.1)
Mako (0.8.1)
MarkupSafe (0.18)
nose (1.3.0)
Paste (1.7.5.1)
PasteDeploy (1.5.0)
PasteScript (1.7.5)
PIL (1.1.7)
psycopg2 (2.5)
py-bcrypt (0.3)
pyasn1 (0.1.7)
PyCAPTCHA (0.4)
pycassa (1.9.0)
pycountry (0.14.8)
pycparser (2.09.1)
pycrypto (2.6)
Pygments (1.6)
pylibmc (1.2.3)
Pylons (0.9.7)
pytz (2013b)
repoze.lru (0.6)
requests (1.2.3)
Routes (1.11)
rsa (3.1.1)
simplejson (3.3.0)
six (1.3.0)
snudown (1.1.5)
SQLAlchemy (0.7.4)
stripe (1.9.1)
Tempita (0.5.1)
thrift (0.9.0)
waitress (0.8.5)
WebError (0.10.3)
WebHelpers (1.3)
WebOb (1.2.3)
WebTest (2.0.6)
Whoosh (2.4.1)
wsgiref (0.1.2)
zope.interface (4.0.5)
My hypothesis is that at least one of these packages requires WebOb==1.0.8 and at least one other requires WebOb>=1.2
I've setup a virtualenv for the Reddit install and set it up with the --no-site-packages option so that I'm only dealing with the packages I need for Reddit. I manually installed everything that I think I need. So this is actually the minimum set of packages. I need each of them, but perhaps not all of them are the correct versions. The Reddit installer doesn't specify versions for every package, only some of them.
So how do I track down these dependencies? How do I get a list of the requirements for each of the packages installed in the virtualenv?
And where is the file: "build/bdist.linux-i686/egg/pkg_resources.py" coming from? I can't find it anywhere in my system. And the Mac is not linux so this seems odd.
I'm a very experienced programmer, C++, Java, Object Pascal, Objective C, etc. but not an expert Python programmer yet. So the Python package system is too much of a black box to me at this point. I can use pip and run setup.py scripts but I don't yet grok them.
The problem was coming from having a version 2.0.6 of the WebTest library. This version was the one requiring WebOb>=1.2.
To determine the requirements for the python modules. I cd'd into the site-packages directory for the virtual env and then ran:
grep WebOb *.egg-info/requires.txt
which returned:
Pylons-0.9.7-py2.7.egg-info/requires.txt:WebOb>=0.9.6.1
WebError-0.10.3-py2.7.egg-info/requires.txt:WebOb
WebTest-2.0.6-py2.7.egg-info/requires.txt:WebOb>=1.2
where I was able to see that WebTest was the conflicting package.
I was then able to go into my Ubuntu install to see what package for WebTest was installed found that WebTest 1.3.3 worked on the standard Ubuntu Reddit install. So I uninstalled both WebOb 1.2 and WebTest 2.0.6 and then ran:
pip install webob==1.0.8
pip install webtest==1.3.3
This got rid of the conflict WebOb versions conflict. I still can't yet get Reddit to run, but at least I removed this block.
Reddit's installer adds an Ubuntu private package repository. The PPA includes many variants of Ubuntu python packages.
If you are running Ubuntu, you can also install the PPA.