I have the following python file.
import sys
sys.path.insert(1, '/usr/local/google_appengine')
sys.path.insert(1, '/Users/vinay/google-cloud-sdk/platform/google_appengine/')
sys.path.insert(1, '/Users/vinay/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
from google.appengine.api import users
This is a unit test python file.
However, when I run the unit test I get the following error
/Users/vinay/App-Engine/xxxx/x/env/bin/python xxx/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py /Users/vinay/App-Engine/xxxx/x/tests/test_oauth2callback.py::TestOauth2callback true
Testing started at 10:12 PM ...
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py", line 129, in <module>
module = loadSource(a[0])
File "/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py", line 43, in loadSource
module = imp.load_source(moduleName, fileName)
File "/Users/vinay/App-Engine/xxxx/x/tests/test_oauth2callback.py", line 6, in <module>
from google.appengine.api import users
ImportError: No module named appengine.api
Process finished with exit code 1
Related
I am writing a small unittest for my method move(). The application is running but when I do python -m unittest app.test.test_move_items, it fails with the following error:
ImportError: Failed to import test module: test_move
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "/Users/daniel/app/test/test_move.py", line 13, in <module>
from app.move_items import move
File "/Users/daniel/apps/app/move.py", line 29, in <module>
from helpers.calculator import determine_move_amount
ModuleNotFoundError: No module named 'helpers'
If i do python app/move.py, the output is correct.
The folder structure is as follows:
app
helpers
|-calculator.py
move_items.py
test
|-test_move_items.py
move_items.py
from helpers.calculator import determine_move_amount
def move(list_of_items, move_by):
pass
There is init.py file in app and the test directory as well.
I am using the ChatterBot library to create a chatbot and I have come across this error. I tried to create a chatbot object in my program but I get this compile time error
Traceback (most recent call last):
File "d:\TwitterBot1\Bot1.py", line 123, in <module>
bot = ChatBot('Bot1')
File "D:\Python\lib\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "D:\Python\lib\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "D:\Python\lib\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "D:\Python\lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
ImportError: cannot import name 'util' from partially initialized module 'sqlalchemy' (most likely due to a circular import) (D:\Python\lib\site-packages\sqlalchemy\__init__.py)
I looked into the file that is in the error and the issue is with this import line
from . import util as _util # noqa
and when I try running the __init__.py file, I get this error
Traceback (most recent call last):
File "d:\Python\Lib\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
ImportError: attempted relative import with no known parent package
all of the other imports in the __init__.py file have some file directive of sorts after the "." following the "from" instruction. I am not sure if this file was missing some directive or what.
Can anyone point me in the direction of a fix?
I figured this out. Turns out that sqlalchemy 1.4(verson of this time) is not compatible with the current version of chatterbot so I deleted and reinstalled sqlalchemy with version 1.2. Then there was a time.clock error in one of the files in sqlalchemy so I replaced that with time.perf_counter() and everything works now
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.
I have a Python file that I'm trying to import into a session. The file structure looks like the following
-object_detection
--__init__.py
--export_inference_graphy.py
--protos
---__init__.py
---pipeline_pb2.py
From the export_inference_graph file, I'm trying to import pipeline_pb2.
However, I get the following error.
from object_detection.protos import pipeline_pb2
Traceback (most recent call last):
File "<ipython-input-60-76f12fdd6acf>", line 1, in <module>
from object_detection.protos import pipeline_pb2
ModuleNotFoundError: No module named 'object_detection.protos'; 'object_detection' is not a package
I've also tried the following and each has resulted in the same error.
import sys
sys.path.append('/protos')
import pipeline_pb2
from ..protos import pipeline_pb2
When I try to import multiprocessing in Python 2.7.5 on OS X 10.6.8, I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/util.py", line 40, in <module>
from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags
I also tried to install python2.7.6 with homebrew, but this error still occurs.
It sounds like a circular import issue. Try adding this to the the rest of your imports:
from subprocess import _args_from_interpreter_flags
There is a comment above the function in subprocess.py:
# XXX This function is only used by multiprocessing and the test suite,
# but it's here so that it can be imported when Python is compiled without
# threads.
May be related.