Import error in Python 3.6 with sudo?

2019-08-17 02:00发布

I have written a program that uses Scapy. Python is able to import the scapy module perfectly but using sniff function of scapy requires running the program as administrator. However, running the program as sudo python3 <program_name> produces an import error, why is it so?

Here is the import line : import scapy.all as scapy

2条回答
2楼-- · 2019-08-17 02:43

You can fix it with:

$ sudo pip install scapy

And then try again.

I would recommend using virtualenv to run your program though. Instead of installing package after package in your main environment.

查看更多
一夜七次
3楼-- · 2019-08-17 03:04

As using python3, I would recommend

sudo python3 -m pip install scapy
查看更多
登录 后发表回答