Last modified: May 28, 2025 By Alexander Williams

Install PySocks in Python Easily

PySocks is a Python library that allows you to use SOCKS proxies in your applications. It is useful for anonymity and bypassing network restrictions.

This guide will show you how to install PySocks in Python easily. Follow the steps below to get started.

Prerequisites

Before installing PySocks, ensure you have Python installed. You can check by running:


python --version

If Python is not installed, download it from the official website. Also, ensure pip is available.

Install PySocks Using pip

The easiest way to install PySocks is via pip. Open your terminal or command prompt and run:


pip install PySocks

This will download and install the latest version of PySocks. Wait for the process to complete.

Verify the Installation

After installation, verify PySocks is installed correctly. Run the following command:


pip show PySocks

You should see details about the installed package. If not, check for errors during installation.

Using PySocks in Python

PySocks integrates with Python's socket module. Here’s a simple example to use a SOCKS proxy:


import socks
import socket

# Set up a SOCKS proxy
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket

# Test the connection
try:
    print(socket.gethostbyname("example.com"))
except Exception as e:
    print("Error:", e)

This code sets a SOCKS5 proxy and tests the connection. Replace the proxy details with your own.

Common Issues and Fixes

If you encounter errors, ensure the proxy server is running. Also, check your firewall settings.

For network-related issues, verify your internet connection. If PySocks fails to install, try upgrading pip:


pip install --upgrade pip

Alternative Installation Methods

If pip fails, you can install PySocks from source. Download the source code from GitHub and run:


python setup.py install

This method requires additional tools like setuptools. Ensure they are installed.

Conclusion

Installing PySocks in Python is simple with pip. Follow the steps above to set it up quickly.

PySocks is a powerful tool for proxy support. Use it to enhance your Python projects.

For more Python guides, check out our articles on installing PyAudio or installing PyUSB.