Python wrapper around the solc Solidity compiler
—
Experimental functionality for installing specific versions of the solc compiler binary across different platforms. This feature allows you to manage multiple solc versions and ensures consistent compilation environments.
Installs a specified version of the solc compiler binary for the current or specified platform.
def install_solc(identifier, platform=None):
"""
Install specified version of solc compiler.
Args:
identifier (str): Version identifier (e.g., 'v0.4.24', 'v0.4.1')
platform (str): Target platform ('linux', 'darwin', 'win32').
If None, auto-detected from current system
Returns:
None: Installation is performed, binary installed to ~/.py-solc/
Raises:
ValueError: When identifier or platform is invalid
OSError: When installation fails due to system issues
Note:
This is experimental functionality. Installed binary location:
$HOME/.py-solc/solc-{version}/bin/solc
For older Linux installs, may require setting:
LD_LIBRARY_PATH=$HOME/.py-solc/solc-{version}/bin
"""# Available version identifiers
V0_4_1 = 'v0.4.1'
V0_4_2 = 'v0.4.2'
V0_4_6 = 'v0.4.6'
V0_4_7 = 'v0.4.7'
V0_4_8 = 'v0.4.8'
V0_4_9 = 'v0.4.9'
V0_4_11 = 'v0.4.11'
V0_4_12 = 'v0.4.12'
V0_4_13 = 'v0.4.13'
V0_4_14 = 'v0.4.14'
V0_4_15 = 'v0.4.15'
V0_4_16 = 'v0.4.16'
V0_4_17 = 'v0.4.17'
V0_4_18 = 'v0.4.18'
V0_4_19 = 'v0.4.19'
V0_4_20 = 'v0.4.20'
V0_4_21 = 'v0.4.21'
V0_4_22 = 'v0.4.22'
V0_4_23 = 'v0.4.23'
V0_4_24 = 'v0.4.24'LINUX = 'linux'
OSX = 'darwin'
WINDOWS = 'win32'| Version | Linux | macOS (OSX) | Windows |
|---|---|---|---|
| v0.4.1 | ✓ | ✗ | ✗ |
| v0.4.2 | ✓ | ✗ | ✗ |
| v0.4.6 | ✓ | ✗ | ✗ |
| v0.4.7 | ✓ | ✗ | ✗ |
| v0.4.8 | ✓ | ✓ | ✗ |
| v0.4.9 | ✓ | ✗ | ✗ |
| v0.4.11+ | ✓ | ✓ | ✗ |
Note: Windows support is not available through this installation system.
from solc import install_solc
# Install latest supported version
install_solc('v0.4.24')
# Install specific version
install_solc('v0.4.11')from solc import install_solc, LINUX, OSX
# Install for Linux (useful when cross-compiling)
install_solc('v0.4.24', platform=LINUX)
# Install for macOS
install_solc('v0.4.24', platform=OSX)from solc import install_solc, V0_4_24, V0_4_11
# Using constants for type safety
install_solc(V0_4_24)
install_solc(V0_4_11)You can also install solc versions from the command line:
# Install using Python module
python -m solc.install v0.4.24
# Or using the main module
python -m solc.install v0.4.11from solc import install_solc
try:
install_solc('v0.5.0') # Unsupported version
except ValueError as e:
print(f"Installation failed: {e}")
try:
install_solc('v0.4.24', platform='unsupported_platform')
except ValueError as e:
print(f"Unsupported platform: {e}")
try:
install_solc('v0.4.24')
except OSError as e:
print(f"System error during installation: {e}")Static Binary (v0.4.11+):
Ubuntu Release Package (v0.4.1-v0.4.9):
LD_LIBRARY_PATH environment variableSource Compilation:
Installed binaries are located at:
$HOME/.py-solc/solc-{version}/bin/solcFor older Linux installations, you may need to set:
export LD_LIBRARY_PATH=$HOME/.py-solc/solc-v0.4.24/bin:$LD_LIBRARY_PATHimport os
from solc import compile_source
# Set environment variable to use specific installed version
os.environ['SOLC_BINARY'] = os.path.expanduser('~/.py-solc/solc-v0.4.24/bin/solc')
# Now compilation will use the installed version
result = compile_source(source_code)After installation, verify the binary works:
from solc import get_solc_version_string
import os
# Point to installed binary
os.environ['SOLC_BINARY'] = os.path.expanduser('~/.py-solc/solc-v0.4.24/bin/solc')
# Check version
version = get_solc_version_string()
print(f"Installed solc version: {version}")wget (for downloading releases)git (for source compilation on older versions)xcode-select --install)git (usually included with Command Line Tools)cmake and make (for source compilation)Permission Denied:
chmod +x ~/.py-solc/solc-v0.4.24/bin/solcLibrary Path Issues (Linux):
export LD_LIBRARY_PATH=~/.py-solc/solc-v0.4.24/bin:$LD_LIBRARY_PATHMissing Dependencies (macOS):
xcode-select --install
brew install cmake # if using HomebrewTest installed binary manually:
~/.py-solc/solc-v0.4.24/bin/solc --versionRemove installed versions:
rm -rf ~/.py-solc/solc-v0.4.24/Install with Tessl CLI
npx tessl i tessl/pypi-py-solc