0

I am trying to use scapy and netfilterqueue with python 3.6.1. I created an environment with these installed.. as netfilterqueue will not work on python 3.9.

When I try to run my script: pipenv run python3 test.py

it runs in the correct environment but I get:

PermissionError: [Errno 1] Operation not permitted

When I try to run with sudo: sudo pipenv run python3 test.py

I get:

Warning: Python 3.6.1 was not found on your system…
You can specify specific versions of Python with:
  $ pipenv --python path/to/python

I've verified my libraries are correctly installed on the environment but am just not sure how to pass permissions to run a script. Thanks!

──(kali㉿bad)-[~/Desktop/env]
└─$ pipenv shell                  
Launching subshell in virtual environment...
 . /home/kali/.local/share/virtualenvs/env-_HkHVbK0/bin/activate
WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.
┌──(kali㉿bad)-[~/Desktop/env]
└─$  . /home/kali/.local/share/virtualenvs/env-_HkHVbK0/bin/activate
                                                                                           
┌──(env-_HkHVbK0)(kali㉿bad)-[~/Desktop/env]
└─$ python3
Python 3.6.1 (default, May 12 2021, 17:05:21) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scapy
>>> import netfilterqueue
>>> import sys
>>> sys.path
['', '/home/kali/.pyenv/versions/3.6.1/lib/python36.zip', '/home/kali/.pyenv/versions/3.6.1/lib/python3.6', '/home/kali/.pyenv/versions/3.6.1/lib/python3.6/lib-dynload', '/home/kali/.local/share/virtualenvs/env-_HkHVbK0/lib/python3.6/site-packages']
>>> 
Tim
  • 1
  • How did you set up the project before running `pipenv run python3 test.py`? – chepner May 13 '21 at 15:02
  • I used `pipenv install ` , which I believe makes the environment too if it doesn't already exist.. and that seemed to work. Then I changed the versions of python manually in the two pipefile's in the environment folder. – Tim May 13 '21 at 15:47
  • Take a look at : https://stackoverflow.com/questions/44304988/permissionerror-errno-1-operation-not-permitted/44314951 – Philippe May 13 '21 at 16:33
  • thanks but my issue is it won't let me run the script with sudo. – Tim May 13 '21 at 17:14

1 Answers1

0

I did have similar issue. I managed to solved by running the virtual environment's Python executable with sudo. For example if your virtualenv is ./AwesomeProject, then you could run sudo ./AwesomeProject/bin/python to use the script with the virtualenv with root privileges.

To find where your the virtual environment's Python executable (Ex: ./AwesomeProject/bin/python), inside the virtual env run

whereis python

more info: https://askubuntu.com/questions/234758/how-to-use-a-python-virtualenv-with-sudo