python3 for ubuntu can't find scapy? - python

I'm trying to run a python script using scapy in Ubuntu 14.04. I downloaded python3 with
sudo apt-get install python3
and I'm running the file I have with
sudo python3 <my filename>.py
As for importing scapy into my python file, I've tried
from scapy.all import *
and
import scapy.all
and other variations I've found while browsing the internet. However, none of them work and I keep getting the "No module named 'scapy'" error.
My script worked when I ran it in python2 in the same environment using scapy, but I've made changes specific to python3 in another development environment and now need to run it in python3 in this environment.
Any ideas on how to get this working? I've tried updating python also, but I can't get it to upgrade versions.

You have to install scapy library before using it. By what you write it seems you just installed python3 and not scapy. Either:
install pip3 and then pip3 install scapy to install scapy library for all system
(recommended) or use virtualenv and install the same way inside virtual environment, and then run your script inside the python virtual environment
On usage of virutalenv for python you can easily find many guides. Please, comment if you need assistance on that.

Related

Python Nmap module not found despite already being installed

I am trying to write a port scanning program as part of my course assignment. However, even after downloading Nmap, an error appeared. It says 'nmap' is not accessed by pylance. I cannot access it interactive mode either. I am still very new to programming so any form of help will be much appreciated
As you can see here Nmap is already downloaded.
But...
And...
I tried deleting and re-installing Nmap, that did not work. I searched YouTube for solutions, but a lot of the files and programs they had I did not. I have already downloaded nmap from the website too.
Maybe that happened because you have many interpreter and you installing in another interpreter to fix that you need to change the interpreter you can see the documentation in
https://code.visualstudio.com/docs/python/environments
or you can try using python venv by write this command in your terminal
python -m venv venv
after that activate the venv and activate the venv
.\venv\Scripts\activate
after you activate the venv you just need to install the nmap
pip install python-nmap
I hope this answer can solve your problem
You might have multiple version of python installed. When you run py is opens up 3.10.7 for you. You need to make sure you installed python-nmap for that version.
Apart from using a virtual environment, a quick fix would be to try installing nmap using pip3
pip3 install python-nmap
This will install nmap for your python3 installation. However if you have multiple python3 installations, I would suggest using a virtual environment of the particular python version you want.

How do I run a Python script with sudo? (MAC)

I want to test the keyboard.on_press_key() function, but OSX blocks it naturally. When I try to run it through the terminal using sudo python [pathtofile] I get an import error: "ImportError: No module named keyboard". I tried installing the module using sudo (sudo pip install keyboard) but, even though it installs just fine, I still get the same error. 
What am I doing wrong?
Note that python on macOS refers to the system installation. You should not install packages via pip to the system installation of Python. I'd recommend you to install another Python interpreter e.g. via brew. See www.brew.sh for more info.
Then, it is just a matter of installing Python via
$ brew install python3
After that, simply install your keyboard package again:
$ pip3 install keyboard
That is a error in your script, you probably didnt import the keyboard module before you used. Try adding this in the first lines of your python script:
import keyboard

Why does my virtualenv python3 work fine on my local machine but not when I upload the virtualenv to the server?

If I install a virtualenv on my local machine, activate it and try to run python3 then it works fine (with the imported modules). However, after I send it to the live server (using scp and filezilla) it gives the error:
-bash: /<path>/venv4/bin/python3: cannot execute binary file: Exec format error
This also happens with python and python3.8 in the same package.
I have tried reinstalling virtualenv and pipx, recreating the virtualenv and reuploading a few times.
It seems that it can't find the module, as when I activate the virtualenv on the live server and type "which python3" then it shows me the system python3:
/usr/bin/python3
It also does not work if I try to execute the venv's python3 directly, using the full path.
The reason I'm doing this is because the old virtualenv I was using has stopped working because it can't seem to find the installed modules anymore. I'm not sure why.
Any help would be much appreciated.
I believe some pip packages contain more than just python code, and must be compiled. If your host OS is different from your server OS, or you have different libraries installed, the host-compiled code will not be compatible with your server.
Common practice is to create a file with a list of required packages, using something like
pip freeze > requirements.txt
and rebuild the environment on the server, using something like
pip install -r requirements.txt

awscli running with python 2.7 on OS x Sierra

I'm having an issue with my awscli version + python versions installed on my Mac.
After several tries following this I managed to have it working, however, if i run aws --version I get aws-cli/1.11.170 Python/2.7.10 Darwin/16.7.0 botocore/1.7.28
This confused me because I thought I had just installed python 3.6, so I decided to run which python, and it returned /usr/bin/python
I was still unsure and after some research I found this:
$which python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Now i'm totally unsure which python version is the "main" one and if it is affecting my awscli, i plan to create a restapi using aws SDK with boto3 for Python.
How can i clean my python install or simply make sure my Mac is ready to work with the aws SDK + python?
PS.: I've tried this to uninstall python 2.6, 2.7 and 3.6 (currently installed on my system i suppose) but nothing really happened.
Thanks in advance for the help!
I would recommend creating a virtual environment to create an isolated environment for all the packages in your project. You can create a virtual environment of a specific python version using the following syntax in your shell:
$ python3.6 -m venv env
One you activate the virtual environment, you can use pip to install packages into your local python instance:
$ source env/bin/activate
(env) $ pip install awscli
Whenever you plan to run your application, or install packages for the project, simply activate the virtual environment.
For more information, see the documentation for the venv module in Python's standard library.

python3.4 import visa fails, this worked under python3.5

OK, I loaded Python 3.5 PYVISA, and set up my path variables in Windows, and import visa worked! Yay!
Now I want to create an executable, using cx_Freeze. I try running it, and it says it wants to see Python 3.4.
OK, I load Python 3.4. I add python34 paths to Windows and start up idle, load my script, and try to import visa, no module named visa.
What do I have to do to get the script to run under Python 3.4?
thank you
If you have installed pyvisa by using below command:
pip install pyvisa
Then it gets installed in site packages of python 3.5 (or) site packages of that specific python version (whichever python that is serving at that point of time)
If you want that to be available for all python versions, install it to separate folder and add that path as value to PYTHONPATH (system variable). If there is no such variable, create one. Command to install it to separate folder is:
pip install pyvisa -t c:\external
(Or)
Re-install it using pip from specific python version
C:\Python34\python.exe -m pip install pyvisa

Categories

Resources