ImportError cannot import name - python

I'm trying to run a unittest with the following imports:
from LinearProbeTable import Dictionary
import unittest
import string
import random
class TestDictionary(unittest.TestCase):
(testing code)
In LinearProbeTable I import an excecption:
from Exceptions import DictFullError
The DictFullError is defined as (in Exceptions.py):
class DictFullError(Exception):
pass
I get the following traceback when I try to run the test:
Traceback (most recent call last):
File "/Applications/PyCharm Educational.app/Contents/helpers/pycharm/utrunner.py", line 135, in <module>
module = loadSource(a[0])
File "/Applications/PyCharm Educational.app/Contents/helpers/pycharm/utrunner.py", line 40, in loadSource
module = imp.load_source(moduleName, fileName)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 171, in load_source
module = methods.load()
File "<frozen importlib._bootstrap>", line 1220, in load
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/Users/andrewsalter/.../Prac 9/Testing/task1_autotest.py", line 1, in <module>
from LinearProbeTable import Dictionary
File "/Users/andrewsalter/.../Prac 9/LinearProbeTable.py", line 1, in <module>
from Exceptions import DictFullError
ImportError: cannot import name 'DictFullError'
I don't have a circular dependency, so I'm not sure what's happening.
I'm trying to run this on my laptop, but it worked on my Desktop (I have it all hosted on google drive - I know I should be using Git but I haven't got around to it yet)
EDIT: Could it be due to the fact LinearProbeTable.py is in the parent folder to the testing script?

Related

IDAPython with PyCharm throws: "ModuleNotFoundError: No module named '_ida_hexrays'"

I want to use PyCharm with IDAPython. I setup the Python Interpreter by adding the following path to the "Interpreter Paths":
C:\Program Files\IDA Pro 7.7\python\3
After that, it recognize the modules idaapi and idautils which is a good sign.
I wrote a simple scripts to test it:
import idaapi
import idautils
filename = idaapi.get_input_file_path()
I set a breakpoint on the filename... row and it failed with:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Program Files\IDA Pro 7.7\python\3\ida_hexrays.py", line 12, in <module>
import _ida_hexrays
ModuleNotFoundError: No module named '_ida_hexrays'
It doesn't recognize the modules _ida_hexrays. How can I make it work?
I see that there is a file: C:\Program Files\IDA Pro 7.7\python\3\ida_64\_ida_hexrays.pyd.
In the ida_hexrays.py it throws the error when it try to import it like that:
# Import the low-level C/C++ module
if __package__ or "." in __name__:
from . import _ida_hexrays
else:
import _ida_hexrays

Import error using Python uadt package (machine learning)

I'm tyring to use this program (https://github.com/tbabej/uadt) to test my pcap captures and do some machine learning. I use the command git clone to have everything on my pc, then I use "pip -r install requirements.txt" and then I execute "setup.py install".
Then I need to generate my dataset, so I go to /uadt/uadt/analysis/ and run dataset.py as stated in the Readme, but I get the error
from uadt import config
ImportError: cannot import name 'config' from 'uadt'
What am I doing wrong? Is there another way to install it?
I just need the files in the analysis folder because I've already done the other steps on my own.
Traceback (most recent call last):
File "/usr/local/bin/uadt-dataset", line 33, in <module>
sys.exit(load_entry_point('uadt==0.8.0', 'console_scripts', 'uadt-dataset')())
File "/usr/local/bin/uadt-dataset", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/local/lib/python3.9/dist-packages/uadt-0.8.0-py3.9.egg/uadt/analysis/dataset.py", line 26, in <module>
from uadt.analysis.flow import Flow
File "/usr/local/lib/python3.9/dist-packages/uadt-0.8.0-py3.9.egg/uadt/analysis/flow.py", line 13, in <module>
from uadt import config
ImportError: cannot import name 'config' from 'uadt' (/usr/local/lib/python3.9/dist-packages/uadt-0.8.0-py3.9.egg/uadt/__init__.py)
You can copy the config.py.in file into the uadt folder.
This could fix your import issue.

cannot import name parse_date on python 3

when i'm just importing pandas on Python 3.6.9 this error happens but when importing pandas on python 2.7 it just work fine.
import pandas as pd
this is the console output
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/amir/.local/lib/python3.6/site-packages/pandas/__init__.py", line 177, in <module>
import pandas.testing
File "/home/amir/.local/lib/python3.6/site-packages/pandas/testing.py", line 5, in <module>
from pandas._testing import (
File "pandas/src/testing.pyx", line 4, in init pandas._testing (pandas/src/testing.c:4441)
File "/home/amir/.local/lib/python3.6/site-packages/pandas/types/missing.py", line 5, in <module>
from pandas import lib
File "pandas/lib.pyx", line 1, in init pandas.lib (pandas/lib.c:90894)
File "pandas/tslib.pyx", line 68, in init pandas.tslib (pandas/tslib.c:116506)
ImportError: cannot import name parse_date
can you suggest what to do beside using python 2.7?

ImportError: cannot import name 'execution_result_pb2'

I'm trying to execute the TFX-Airflow tutorial (https://www.tensorflow.org/tfx/tutorials/tfx/airflow_workshop). When I try to connect to the server using airflow webserver -p 8008 it gives me the following error
Traceback (most recent call last):
File "/home/tester/.local/lib/python3.6/site-packages/airflow/models/dagbag.py", line 243, in process_file
m = imp.load_source(mod_name, filepath)
File "/usr/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/tester/airflow/dags/taxi_pipeline_solution.py", line 26, in <module>
from tfx.components import CsvExampleGen
File "/home/tester/Airflow/tfx/tfx/components/__init__.py", line 17, in <module>
from tfx.components.bulk_inferrer.component import BulkInferrer
File "/home/tester/Airflow/tfx/tfx/components/bulk_inferrer/component.py", line 19, in <module>
from tfx.components.bulk_inferrer import executor
File "/home/tester/Airflow/tfx/tfx/components/bulk_inferrer/executor.py", line 26, in <module>
from tfx.dsl.components.base import base_executor
File "/home/tester/Airflow/tfx/tfx/dsl/components/base/base_executor.py", line 33, in <module>
from tfx.proto.orchestration import execution_result_pb2
ImportError: cannot import name 'execution_result_pb2'
My system is running on Ubuntu 20.04 and I have a virtual environment with all the dependencies installed as listed on the linked tutorial. I've used the 8008 port since I was getting an error with the 8080 port (that the connection is in use).
I read that it could be because the module is missing/circular dependent imports but I'm not sure which packages are responsible. I cannot find an execution_result_pb2.py file on my system (assuming it is a file). Does anyone know how to solve this?

How to fix AttributeError in App Engine Flex when using grpc and cloud-datastore?

When I deploy a python3 application using Google App Engine Flex I get the following error:
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/vmagent/app/run.py", line 8, in <module>
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
File "/home/vmagent/app/application/__init__.py", line 43, in create_app
from .main import main as main_blueprint
File "/home/vmagent/app/application/main/__init__.py", line 5, in <module>
from . import cron_jobs, views
File "/home/vmagent/app/application/main/cron_jobs.py", line 4, in <module>
from google.cloud import datastore
File "/env/lib/python3.6/site-packages/google/cloud/datastore/__init__.py", line 60, in <module>
from google.cloud.datastore.batch import Batch
File "/env/lib/python3.6/site-packages/google/cloud/datastore/batch.py", line 24, in <module>
from google.cloud.datastore import helpers
File "/env/lib/python3.6/site-packages/google/cloud/datastore/helpers.py", line 29, in <module>
from google.cloud.datastore_v1.proto import datastore_pb2
File "/env/lib/python3.6/site-packages/google/cloud/datastore_v1/__init__.py", line 18, in <module>
from google.cloud.datastore_v1.gapic import datastore_client
File "/env/lib/python3.6/site-packages/google/cloud/datastore_v1/gapic/datastore_client.py", line 18, in <module>
import google.api_core.gapic_v1.client_info
File "/env/lib/python3.6/site-packages/google/api_core/gapic_v1/__init__.py", line 26, in <module>
from google.api_core.gapic_v1 import method_async # noqa: F401
File "/env/lib/python3.6/site-packages/google/api_core/gapic_v1/method_async.py", line 20, in <module>
from google.api_core import general_helpers, grpc_helpers_async
File "/env/lib/python3.6/site-packages/google/api_core/grpc_helpers_async.py", line 145, in <module>
class _WrappedStreamUnaryCall(_WrappedUnaryResponseMixin, _WrappedStreamRequestMixin, aio.StreamUnaryCall):
AttributeError: module 'grpc.experimental.aio' has no attribute 'StreamUnaryCall'
My requirements.txt file include the following:
google-cloud-datastore==1.12.0
grpcio==1.27.2
The reason I am using grpcio version 1.27.2 instead of the most recent 1.29.0 is because of the information shown here
Can somebody help?
I just encountered the same issue, so this may help you out. I've noticed that google-api-core is also a dependency and it was recently updated (specifically around the grpc_helpers_async), so I just pinned it to version 1.17.0 and it resolved the issue. Just add this to your requirements:
google-api-core==1.17.0

Categories

Resources