Installing Scapy on Android - python

I did an installation on android using the follow commands on android:
apt install python
pip install scapy
everything is fine for now, but when i run scapy i got this error -----see error
This error does not happen to me in conda or kali, it appears to be exclusive for android.
ERROR: Loading module scapy.layers.netflow
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/main.py", line 143, in _load
mod = importlib.import_module(module)
File "/data/data/com.termux/files/usr/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/layers/netflow.py", line 112, in <module>
class NetflowRecordV5(Packet):
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/layers/netflow.py", line 127, in NetflowRecordV5
ByteEnumField("prot", IP_PROTOS["tcp"], IP_PROTOS),
File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/scapy/dadict.py", line 49, in getitem
return getattr(self, attr)
AttributeError: 'DADict' object has no attribute 'tcp'
The android device is rooted. I hope someone is familiar with this error and can help. Thanks

i did this on my phone but it looks require root access

Related

How to create a conda environment that can switch between arm64 and x86_64 architecture?

I am using an Apple Mac M1 with MacOS Monterey
I want to create a virtual environment with conda and be able to switch between arm64 and x86_64 architecture. for example
arm64 python3 run.py
or
x86_64 python3 run.py
currently i am stuck at this error
(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
the full traceback is below
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 857, in _get_module
return importlib.import_module("." + module_name, self.__name__)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/onnx/config.py", line 35, in <module>
from PIL import Image
File "/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/Image.py", line 114, in <module>
from . import _imaging as core
ImportError: dlopen(/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so, 0x0002): tried: '/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/_imaging.cpython-38-darwin.so' (no such file)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 857, in _get_module
return importlib.import_module("." + module_name, self.__name__)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/models/__init__.py", line 19, in <module>
from . import (
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/models/layoutlm/__init__.py", line 22, in <module>
from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/models/layoutlm/configuration_layoutlm.py", line 22, in <module>
from ...onnx import OnnxConfig, PatchingSpec
File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 847, in __getattr__
module = self._get_module(self._class_to_module[name])
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 859, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.onnx.config because of the following error (look up to see its traceback):
dlopen(/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so, 0x0002): tried: '/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/_imaging.cpython-38-darwin.so' (no such file)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "run.py", line 7, in <module>
from transformers import TFAutoModel, AutoTokenizer
File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 847, in __getattr__
module = self._get_module(self._class_to_module[name])
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 859, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.models.auto because of the following error (look up to see its traceback):
Failed to import transformers.onnx.config because of the following error (look up to see its traceback):
dlopen(/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so, 0x0002): tried: '/Users/name/Library/Python/3.8/lib/python/site-packages/PIL/_imaging.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/_imaging.cpython-38-darwin.so' (no such file)
How can I create a conda environment that can switch between arm64 and x86_64 architectures?
Not possible. You must create two separate environments.

Why does pysmell installation in vscode produces this error?

I have been trying to install pysmell in vscode but there seem to generate this error whenever i do that. Can someone help me understand and resolve this. Thank you!
Traceback (most recent call last):
File "C:\Users\abhil\AppData\Local\Programs\Python\Python39\Scripts\pysmell-script.py", line 33, in <module>
sys.exit(load_entry_point('pysmell', 'console_scripts', 'pysmell'))
File "C:\Users\abhil\AppData\Local\Programs\Python\Python39\Scripts\pysmell-script.py", line 25, in importlib_load_entry_point
return next(matches).load()
File "C:\Users\abhil\AppData\Local\Programs\Python\Python39\lib\importlib\metadata.py", line 77, in load
module = import_module(match.group('module'))
File "C:\Users\abhil\AppData\Local\Programs\Python\Python39\lib\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 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\abhil\AppData\Local\Programs\Python\Python39\lib\site-packages\pysmell\tags.py", line 17, in <module>
from pysmell.codefinder import ModuleDict, processFile
File "C:\Users\abhil\AppData\Local\Programs\Python\Python39\lib\site-packages\pysmell\codefinder.py", line 13, in <module>
import __builtin__
ModuleNotFoundError: No module named '__builtin__'
I was following this link (https://code.google.com/archive/p/pysmell/) for the installation process. I have already done python setup.py install and python setup.py develop. the problem is in the import pysmell part.
Pysmell uses the module __builtin__, which was renamed to builtins in Python 3. You might have to switch to Python 2, or find a different alternative to Pysmell.

Azure function failing after successfull deployment with OSError: [Errno 107]

The function was working before the last deployment. It is used for NLC and we are running two functions for two different languages. For the new deployment we removed some code which was only used for one language and mirrored the code to be equal to the other language. Azure CLI tells us:
Upload completed successfully.
Deployment completed successfully.
But when trying to invoke the function afterwards it either returns 500 without a body or it returns 404 with:
<html>
<head>
<title>404 Not Found</title>
</head>
<body bgcolor="white">
<center>
<h1>404 Not Found</h1>
</center>
<hr>
<center>nginx</center>
</body>
</html>
The stacktrace we can see in the monitoring is the following:
Exception while executing function: Functions.classify Result: Failure
Exception: OSError: [Errno 107] Transport endpoint is not connected: '/home/site/wwwroot/.python_packages/lib/site-packages'
Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 271, in _handle__function_load_request
func = loader.load_function(
File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call
return func(*args, **kwargs)
File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/classify/__init__.py", line 4, in <module>
File "/home/site/wwwroot/classify/predict.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/text/all.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/basics.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/data/all.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/fastai/torch_basics.py", line 1, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/torch/__init__.py", line 482, in <module>
File "/home/site/wwwroot/.python_packages/lib/site-packages/torch/serialization.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 971, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 914, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1342, in find_spec
File "<frozen importlib._bootstrap_external>", line 1314, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1443, in find_spec
File "<frozen importlib._bootstrap_external>", line 1483, in _fill_cache
Commands used for deployment were the following, which worked before:
pip3 install --target="./.python_packages/lib/site-packages" -r requirements.txt
func azure functionapp publish [functionapp name] --no-build
Deleting the python packages and rebuilding etc. did not change anything.
I tried creating a new function app from scratch but it shows the same errors.
I tried to deploy from the folder of the other language with one file swapped (classifier language model) but it
showed the same error. I fear trying to redeploy the working language
for testing as it is working and I don't want to kill it.
It seems to be happening somewhere during module import. Though I am not sure how it was working before (as you mentioned), but I suggest you not to do pip3 install manually and remove --no-build flag to let the func azure functionapp publish handle that. Just make sure you have the requirements.txt in the root.
# no pip install manually
# without --no-build flag
func azure functionapp publish [functionapp name]

AttributeError: module 'pip._internal.download' has no attribute 'HTTPAdapter'

I recently upgraded my pip to 19.3. When I did that I cannot use any pip commands. OS - Mac
When I googled and researched more, most of the suggestions were to downgrade the pip package. However, even when I tried that I am getting the same result. In fact, force installs or uninstall or sudo commands nothing works.
Traceback (most recent call last):
File "/Users/.virtualenvs/myvenv/bin/pip", line 10, in <module>
sys.exit(main())
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/main.py", line 45, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 21, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 17, in <module>
from pip._internal.download import unpack_url
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/wrapt/importer.py", line 158, in load_module
notify_module_loaded(module)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/wrapt/decorators.py", line 443, in _synchronized
return wrapped(*args, **kwargs)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/wrapt/importer.py", line 136, in notify_module_loaded
hook(module)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip_system_certs/wrapt_pip.py", line 8, in apply_patches
override_ssl_handler(download)
File "/Users/.virtualenvs/myvenv/lib/python3.7/site-packages/pip_system_certs/wrapt_pip.py", line 17, in override_ssl_handler
class SslContextHttpAdapter(download.HTTPAdapter):
AttributeError: module 'pip._internal.download' has no attribute 'HTTPAdapter'
Can somebody help, please?
This appears to be because you installed the pip-system-certs package, which hooks into pip internals in a way that was never supported. This promptly broke as soon as you updated pip and the stuff pip-system-certs wanted to mess with got changed.
You will at least need to get rid of pip-system-certs. It looks like it was installed in a virtualenv, so you can probably just deactivate the env and make a new one... but if so, it seems like you would have already tried that. If you didn't already try that, make sure to try it next time! If you did already try that, then you probably wrecked more stuff than we can see, and you may need more drastic measures, such as a full Python reinstall.
What worked for me was to go to <your conda environment>\Lib\site-packages and remove all occurences of pip-system-certs. In my case it was one file and two folders.
pip-tools~=4.2.0 is compatible with pip>=19.3

How to fix ImportError "_psutil_linux" on Heroku

I need psutil in my code but I get the error "importError _psutil_linux" on Heroku
it's for a status application on the use of the system and what's left of free.
I've already tried:
- to force the installation with pip (not work)
- to change the version with the file requirements.txt (not work)
requirements.txt :
Unidecode==1.0.22
youtube_dl==2018.7.21
chardet==3.0.4
urlextract==0.8.3
feedparser==5.2.1
requests==2.18.4
setuptools==40.2.0
aiohttp==1.0.5
urllib3==1.22
discord.py==0.16.12
psutil==5.4.7
pip==9.0.3
pyparsing==2.2.0
Pillow==5.3.0
beautifulsoup4==4.6.3
httplib2==0.11.3
imgurpython==1.1.7
keyboard==0.13.2
google_api_python_client==1.7.4
pyfiglet==0.7.5
pylast==2.4.0
r6sapi==0.8.0
raven==6.9.0
raven_aiohttp==0.7.0
tabulate==0.8.2
typing==3.6.6
my use of psutil :
import psutil
CPU = psutil.cpu_percent()
RAM =psutil.virtual_memory().percent
(in a discord bot command.)
Traceback (most recent call last):
File "/app/cogs/owner.py", line 65, in load
self._load_cog(module)
File "/app/cogs/owner.py", line 946, in _load_cog
mod_obj = importlib.import_module(cogname)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
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 "/app/cogs/cyvgeneral.py", line 7, in <module>
import psutil
File "lib/psutil/__init__.py", line 100, in <module>
from . import _pslinux as _psplatform
File "lib/psutil/_pslinux.py", line 26, in <module>
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux'
I expect Psutil to load correctly.
thank you in advance.

Categories