Scapy not working with Python 3.6. Import problems with Python? - python-3.x

I am trying to test a simple code that will inspect a .pcap file using scapy. My OS is Ubuntu 18.04 and my Python version is 3.6.
However when I do: from scapy.all import * I get the error message ModuleNotFoundError: No module named 'scapy.all'.
When I change this to be from scapy import *, I get an error later in my code when I try and use the scapy sendrecv sniff function. I get the error NameError: name 'sniff' is not defined. Note if I switch from sniff() to rdpcap() I get the same error but its now "rdpcap is not defined".
I've read through a bunch of previous stack overflow answers and nothing is helping. My python script name is "pcap_grapher.py", so the issue is not the script name being scapy.py.
When I run pip3 install scapy in the terminal I get the message Requirement already satisfied: scapy in /home/vic/.local/lib/python3.6/site-packages (2.4.4)
I've also tried running pip3 install --pre scapy[basic] as the docs recommend here: https://scapy.readthedocs.io/en/latest/installation.html but it didn't help.
Any advice would be greatly appreciated. I am super stuck.

First off, you will never be able to import sniff() from scapy, since it is within the submodule scapy.all. There are two ways I can think of to fix this:
Since you're on Ubuntu, try running sudo apt-get install python3-scapy and see if it lets you run from scapy.all import sniff now.
Check the path that python is currently pulling from by typing the following in terminal:
$ which scapy
/location-of-scapy-on-your-system
Then run
$ python
>>> import os
>>> scapy_path = "/location-of-scapy-on-your-system"
>>> if not scapy_path in os.sys.path: os.sys.path.append(scapy_path)
That should hopefully fix things. If not, it's possible you installed the wrong version of scapy: you can check this by running
$ python
>>> import scapy
>>> print(scapy.__version__)

Related

XGBoost module not found in site-packages. Imports but doesn't work. (mac OS)

I was able to install xgboost on my mac and have it so that I can import the module without any errors. However I cannot use it. When I try to import XGBRegressor. I get the following error :
cannot import name 'XGBRegressor' from 'xgboost' (unknown location).
Some of the support for this type of problem says that there may be more than one xgboost location, and that python is selecting the incorrect xgboost, however I have not been able to find how to fix this problem.
When I print the xgboost.__file__ location, it returns 'None'. However I know its in the site-packages folder in my python path.
I have python 3.9
Maybe this.
conda install -c conda-forge xgboost=0.6a2
Then, restart Spyder and re-run!

ImportError cannot import 'langauge' from 'google.cloud' (unknown location)

I'm trying to incorporate google-cloud-language to use sentiment analysis. I followed the guide on the google documentation website, like so:
from google.cloud import language
When I run the script I receive the following error:
ImportError cannot import 'langauge' from 'google.cloud' (unknown location)
I try to run the script like so:
python3 scriptName.py
I've installed google-cloud-language like so:
pip3 install gooogle-cloud-language
pip install google-cloud-language
I've done that in a virtual environment and outside a virtual environment.
Nothing works. How do I properly set up my script to successfully import the NLP module from google cloud?
Happy to see that you resolved your issue. However, I would like to point some things out:
In the error that you posted in the description there is a typo. It looked for a module named langauge instead of language.
pip3 install gooogle-cloud-language and python3 -m pip install google-cloud-language should be equivalent but that may not always be the case. For example when they are not in the same path. Check this answer for more details.
As I was writing this question and going through other similar questions on stackoverflow, I found another command to try and it seems to have worked.
python3 -m pip install google-cloud-language
I did this inside my virtualenv. It could also work outside of one, but because I got it working, I did not test the outside virtualenv case.

Import error, there is no module named numpy, but it says that it is installed?

So I trying to install and run from MSFT the cntk, you know, just for fun. Anyway, I keep getting this error which says:
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Now I have looked around here a little and I found a post saying that I needed to install the latest version of NumPy, but when I go to do that, I get back this:
Requirement already satisfied: NumPy in c:\users\username\appdata\local\continuum\anaconda3\envs\cntk-py34\lib\site-packages
SO I really have no idea what is going on here.
Anyway, thanks in advance.
Is your IDE linked to Anaconda env? If you open up the Anaconda prompt and import numpy do you get the same error?
You probably have an environment outside of Anaconda which does not have numpy installed.
In my case, I was executing [filename].py from the Anaconda prompt as I would a batch file and was getting this error. I confirmed numpy was install by executing pip list.
Funning python and passing the script file name as an argument, eg python [filename].py, correctly imported the numpy module and executed the script without error.

issue plotting .cap files ScaPy Python3

After reading .cap file using rdpcap successfully, I've been trying to use the function pdfdump but it keeps giving me an error:
"AttributeError: 'SingleTexRunner' object has no attribute 'texoutput' "
here's my code:
from scapy.all import *
import pyx
a = rdpcap("the file path..")
a.pdfdump("output filename")
anyone got an idea how to solve this issue?
Use sudo apt-get install python3-pyx on Linux(Debian, Ubuntu...) to install pyx and its dependencies; installing pyx with pip install pyx is not enough.
I'm using Python 3.6.0
I've installed scapy with:
pip3 install scapy-python3
Using wireshark 2.2.3, I saved a dump using the default file format which is .pcapng
I've used the same code as you :
from scapy.all import *
import pyx
a = rdpcap("test.pcapng")
a.pdfdump("test.pdf")
and I obtain a valid pdf.
Don't run scapy (if you use the command line) or your script as root. This fixed it for me.

Python ImportError no module named statistics after downloading

I'm trying to run my code and I don't know what specific package I need in order to get my import statement to work. Below is my header and I keep getting an error saying ImportError no module named statistics. I have looked at a bunch of different pages to see where I can download a solution, but I am trapped. I know my code works because I ran it on my schools lab. If anyone can help, that' be great!
Just note I am a beginner and am using Linux on my virtual machine with Python 2.7
import sys
import requests
import matplotlib.pyplot as plt
import statistics as stat
Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)
It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.
You need to be using python 3.4 to import statistics. Upgrade to the current version and you should have no problems.

Resources