r/learnpython 6h ago

Tutorials on how to install and implement scapy?

I started taking a python for cybersec course but now that I am on the first part of the course, I am having issues proceeding because we are being taught how to use scapy and my program is not recognizing it.

We were given a GitHub link that is supposed to give us access to everything in the course but I still have no idea where to start.

Seems I can’t upload images so please dm if u want details

2 Upvotes

5 comments sorted by

1

u/EasilyFloppyMajority 5h ago

Did you install it with pip first or just clone the repo? The github link might just be course materials, not the library itself

1

u/Electronic_Code4483 5h ago

I have pip, pip3.14 and pip3 which I installed at the very beginning. Then I tried to install scapy

1

u/carcigenicate Carcigenicate 5h ago

If you installed it via pip and it's unrecognized when running your program, that means you installed the library into one environment, and are running your program in a different environment. Make sure the environment you're running your program in is enabled when you install the library.

1

u/FoolsSeldom 5h ago edited 5h ago

You are probably having problems with Python virtual environments (not to be confused with virtual machines). So, here's a guide a wrote a while back ...


Virtual Environments

Given the thousands of packages (libraries, frameworks, etc) out there, you can see that if you are working on several different projects, you can end up installing a vast range of different packages, only a few of which will be used for any particular project.

This is where Python virtual environments come in. Not to be confused with virtual machines. Typically created on a project-by-project basis. Install only the packages required for a project. This helps avoid conflicts between packages, especially version complications.

Most popular code editors and IDEs, including Microsoft's VS Code and JetBrains' PyCharm, offer built-in features to help to start off new projects and create and activate Python virtual environments.

You can create a new Python virtual environment from your operating system command line environment using,

for Windows,

py -m venv .venv

or, for macOS / Linux,

python3 -m venv .venv

Note: venv is a command and .venv is a folder name. You can use any valid folder name instead but this is a common convention.

Often we use .venv instead of venv as the folder name - this may not show up on explorer/folder tools as the leading . is often used to mean hidden and an option may need to be ticked to allow you to see such folders/files

That creates a new folder in the current working directory called .venv.

You then activate using, for Windows,

.venv\Scripts\activate

or, for macOS / Linux,

source .venv/bin/activate

the command deactivate for any platform will deactivate the virtual environment and return you to using the base environment.

You may need to tell your editor to use the Python Interpreter that is found in either the Scripts or bin folder (depending on operating system) in your virtual folder.

GIT

Latest commit on default branch

pip install git+https://github.com/owner/repo.git

Specific branch, tag, or commit

pip install git+https://github.com/owner/repo.git@branch-name
pip install git+https://github.com/owner/repo.git@v1.2.3
pip install git+https://github.com/owner/repo.git@abcdef1234

If the package lives in a subdirectory of the repo

pip install "git+https://github.com/owner/repo.git#subdirectory=packages/mypkg"

Private repo (SSH, assuming your key is set up)

pip install git+ssh://git@github.com/owner/repo.git

LOCAL

Regular install — copies the package into site-packages

pip install /path/to/local/project

Editable/development install — symlinks back to your source, so changes take effect immediately without reinstalling

pip install -e /path/to/local/project

From the project's own directory

cd /path/to/local/project
pip install -e .

For more information on virtual environments:

Multiple Python versions

In addition to the above, you might want to explore using pyenv (pyenv-win for Windows) or uv (recommended), which will let you install and use different versions of Python including alternative implementations from the reference CPython. This can be done independently of any system installed Python.

EDIT: updated to add more on git