"ImportError: No module named exceptions" when running Celery - python

I'm attempting to run a Django app that uses Celery and I'm receiving the following error:
import djcelery
File "/Library/Python/2.7/site-packages/djcelery/__init__.py", line 25, in <module>
from celery import current_app as celery # noqa
File "/Library/Python/2.7/site-packages/celery/__compat__.py", line 135, in __getattr__
module = __import__(self._object_origins[name], None, None, [name])
File "/Library/Python/2.7/site-packages/celery/_state.py", line 18, in <module>
from celery.utils.threads import LocalStack
File "/Library/Python/2.7/site-packages/celery/utils/__init__.py", line 24, in <module>
from celery.exceptions import CPendingDeprecationWarning, CDeprecationWarning
File "/Library/Python/2.7/site-packages/celery/exceptions.py", line 15, in <module>
from billiard.exceptions import ( # noqa
ImportError: No module named exceptions
billiard is installed and the exceptions module does exist, and I'm able to import billiard.exceptions via Python's interactive prompt without issues. It seems that celery is failing to import billiard. Any ideas?

Related

Import error: No module named 'secrets' - python manage.py not working after pull to Digital Ocean

I'm following along a course - Django development to deployment.
After pulling it to Digital Ocean everything else ran smoothly. Until
I tried running python manage.py help
(env) djangoadmin#ubuntu-1:~/pyapps/btre_project_4$ python manage.py help
and I get this error.
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/__init__.py", line 16, in setup
from django.urls import set_script_prefix
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/base.py", line 9, in <module>
from .exceptions import NoReverseMatch, Resolver404
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/exceptions.py", line 1, in <module>
from django.http import Http404
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/__init__.py", line 2, in <module>
from django.http.request import (
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/request.py", line 10, in <module>
from django.core import signing
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/utils/crypto.py", line 6, in <module>
import secrets
ImportError: No module named 'secrets'
I'm a newbie and have been stuck on this for a while. I just want to know what could possibly cause this.
The secrets module was added to Python in version 3.6. Your host is using Python 3.5, hence the secrets module is unavailable. You need a host with Python 3.6+, or a version of Django that doesn't depend on the secrets module
Had the same issue, solved it by specifying the python version I have installed. i.e
$ python3
>>> import secrets
>>> secrets.token_hex(16)

Target WSGI script can't be load as python module

Flask rest API throwing 500 error with 'Target WSGI script can't load as cannot be loaded as Python module' with below logs and in application .wsgi file all looks good.
from flask import Flask, request, g
File "/usr/local/lib/python2.7/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/usr/local/lib/python2.7/site-packages/werkzeug/__init__.py", line 152, in <module>
__import__('werkzeug.exceptions')
File "/usr/local/lib/python2.7/site-packages/werkzeug/exceptions.py", line 71, in <module>
from werkzeug.wrappers import Response
File "/usr/local/lib/python2.7/site-packages/werkzeug/wrappers.py", line 26, in <module>
from werkzeug.http import HTTP_STATUS_CODES, \\
File "/usr/local/lib/python2.7/site-packages/werkzeug/http.py", line 28, in <module>
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request
When I debug through werkzeug/http.py file I came across the below code and in python command line from urllib2 import parse_http_list is working fine but in code, it is going to exception block.
from urllib2 import parse_http_list as _parse_list_header
except ImportError: # pragma: no cover
from urllib.request import parse_http_list as _parse_list_header
The module urllib.request is for Python 3. You are using python 2.
From Werkzeug 2.0.0 changelogs:
Drop support for Python 2 and 3.5
Either downgrade Werkzeug or upgrade to latest python 3 release.

Can only run my copy_files.py from one directory

I can run my copy_files.py script from only one directory.
When I run it from other directories, I get the following errors:
Traceback (most recent call last):
File "./copy_py", line 36, in <module>
import paramiko
File "/usr/local/lib/python3.6/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/local/lib/python3.6/site-packages/paramiko/transport.py", line 56, in <module>
from paramiko.dsskey import DSSKey
File "/usr/local/lib/python3.6/site-packages/paramiko/dsskey.py", line 27, in <module>
from cryptography.hazmat.primitives.asymmetric.utils import (
File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py", line 9, in <module>
from asn1crypto.algos import DSASignature
File "/usr/local/lib/python3.6/site-packages/asn1crypto/algos.py", line 26, in <module>
from .core import (
File "/usr/local/lib/python3.6/site-packages/asn1crypto/core.py", line 53, in <module>
import copy
File "/home/xjacrawf/work/pyth/copy.py", line 106, in <module>
cli = paramiko.client.SSHClient()
AttributeError: module 'paramiko' has no attribute 'client'
I have tried to remove all of the script's body, even renamed the script.
#!/usr/local/bin/python3.6
import sys
sys.path.insert(0, "/usr/local/lib/python3.6/site-packages")
import cx_Oracle
import glob
import os
import time
import paramiko
from scp import SCPClient
cli = paramiko.client.SSHClient()
cli.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
I expect the script to establish a connection, and it just errors.
I run the script from the first directory it ran from $MDS_SRC/ and it runs fine.
I can copy the entire script to my local directory , and it errors out.

How to fix 'ImportError: cannot import name base' when deploying to app engine standard environment?

I have created a simple, Google App Engine application that works with the Google docs api.
it requires the app_engine module from google.auth (from google.auth import app_engine), which I have installed in a /lib folder and added vendor.add('lib') to appengine_config.py
However, when I deploy from google cloud SDK to the app engine standard environment, I am getting the following error:
'importError: cannot import name base'
I am also getting the error:
'ImportError: No module named pyasn1.codec.der'
For both issues I have doubled checked that the base and pyasn1.codec.der modules are actually present in the lib folder. In both cases they are.
Does anyone have any idea what the problem might be?
from google.auth import app_engine
import googleapiclient.discovery
Full tacebacks here:
base
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/main.py", line 23, in <module>
from google.auth import app_engine
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/app_engine.py", line 29, in <module>
from google.auth import crypt
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/__init__.py", line 38, in <module>
from google.auth.crypt import base
ImportError: cannot import name base
pyasn1.codec.der
traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/main.py", line 23, in <module>
from google.auth import app_engine
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/app_engine.py", line 29, in <module>
from google.auth import crypt
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/__init__.py", line 39, in <module>
from google.auth.crypt import rsa
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/rsa.py", line 27, in <module>
from google.auth.crypt import _python_rsa
File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/_python_rsa.py", line 24, in <module>
from pyasn1.codec.der import decoder
ImportError: No module named pyasn1.codec.der
Make sure that the Python modules and objects are properly installed.
Note that in App Engine Python runtime environment, Python client libraries must be vendored into your application as they are not installed in it.
More references are discussed here[1] specific for Google Docs API.
Also make sure that you have obtained credentials with [2]:
from google.auth import app_engine
credentials = app_engine.Credentials()
Since the error is coming from google.auth.crypt module you may also check on this page[3] for more info.
[1] https://developers.google.com/docs/api/how-tos/libraries#python
[2] https://github.com/googleapis/google-auth-library-python/blob/master/docs/user-guide.rst#the-app-engine-standard-environment
[3] https://google-auth.readthedocs.io/en/latest/reference/google.auth.crypt.html#module-google.auth.crypt
I had the same problem, and I go to "google" directory and delete the "auth" manually.
After I run
pip install google-auth
and it's start working.

Run Python program as administrator from command line

I'm trying to run my program as an administrator from the command line. Seems quite easy but I'm struggling.
I started with this, which works fine launched from the Python IDLE:
import dropbox, pymysql, shlex, shutil, subprocess
import logging
import sshtunnel
from sshtunnel import SSHTunnelForwarder
# Main program starts here
print("Hello World!")
but that gave an error as follows:
pi#jsmd:~ $ sudo python /home/pi/Documents/iot_pm2/iot.py
Traceback (most recent call last):
File "/home/pi/Documents/iot_pm2/iot.py", line 3, in <module>
import dropbox, pymysql, shlex, shutil, subprocess
ImportError: No module named pymysql
After some Googling I added two lines at the start:
import sys
sys.path.append("/usr/local/lib/python3.4/dist-packages/")
This also works fine from the Python IDLE but gives a long error trace when run from the command line... and I'm not good enough at understanding how to read the trace and hence what I can do to fix it. (Plus I don't understand why it works from the IDLE as a non-admin but not from the command line as an admin.) Can anyone help?
pi#jsmd:~ $ sudo python /home/pi/Documents/iot_pm2/iot.py
Traceback (most recent call last):
File "/home/pi/Documents/iot_pm2/iot.py", line 5, in <module>
import sshtunnel
File "/usr/local/lib/python3.4/dist-packages/sshtunnel.py", line 25, in <module>
import paramiko
File "/usr/local/lib/python3.4/dist-packages/paramiko/__init__.py", line 30, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/local/lib/python3.4/dist-packages/paramiko/transport.py", line 50, in <module>
from paramiko.dsskey import DSSKey
File "/usr/local/lib/python3.4/dist-packages/paramiko/dsskey.py", line 26, in <module>
from Crypto.PublicKey import DSA
File "/usr/local/lib/python3.4/dist-packages/Crypto/PublicKey/DSA.py", line 89, in <module>
from Crypto import Random
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
from . import FortunaGenerator
File "/usr/local/lib/python3.4/dist-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in <module>
from Crypto.Util import Counter
File "/usr/local/lib/python3.4/dist-packages/Crypto/Util/Counter.py", line 59, in <module>
from Crypto.Util import _counter
ImportError: cannot import name _counter
Thanks.
is the default of python is 3 ? If not try to execute like this: sudo
python3 ... – #Koffee
Thanks to #Koffee we have an answer and this thread can be marked as solved and closed.

Categories