Parseerror importing OpenZeppelin contracts in Pycharm

Hey there,

I use this python code to compile my solidity contract, but I get a parseerror "raise SolcError(
solcx.exceptions.SolcError: ParserError: Source "node_modules/openzeppelin/contracts/token/ERC20/ERC20.sol" not found:". Funnily, it used to always work perfectly and from one day to the other it doesnt...

I am using Pycharm. Please see project folder structure and my solidity contract below. I had to change the solidity compiler to 19 so that I was able to deploy on ganache.
The reason I try to do it with is because I want to learn the foundations instead of just jumping to a framework like brownie or foundry. As I'm a python dev Id love to make it happen with python, but seems like I have to change to Foundry, as Ape is too new still and brownie has been ended.

Steps I took:

  • I deleted the node_modules and reimported it
  • I even created a totally new pycharm project
  • I updated my pycharm, closed it, opened it.
  • I googled and the only solution I got was using juan blanco's solidity extension for vscode, but as I use pycharm, its not a help.
  • I checked for the ERC20.sol contract in my nodemodules and I have it in my directory.

My script "":

# * Goal of the script: compile my sol contracts and saved them as json
# * I need these json files to then interact with the ganache blockchain

import json
from solcx import compile_standard, compile_files, install_solc, set_solc_version
import os

# Install specific version of solc

# * collin's approach to get byte code and abi

#read solidity file -> works
with open("../../contracts/MockDAI.sol", "r") as file:
    mockDAI_file =

#does not work because of the open zeppelin bullshit import...

compiled_sol = compile_standard({
        "language": "Solidity",
        "sources": {"MockDAI.sol": {"content": mockDAI_file}},
        "settings": {
            "outputSelection": {
                "*": {"*": ["abi", "metadata", "evm.bytecode","evm.sourceMap"]}


my project folder structure:

├── contracts/
│   └── MockDAI.sol
├── node_modules/
│   └── @openzeppelin/
│       └── contracts/
│           └── token/
│               └── ERC20/
│                   └── ERC20.sol
├── scripts/
│   └── ganache_deployment_testing/
│       └──
├── package.json
└── package-lock.json

my solidity contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../node_modules/openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockDAI is ERC20 {
    constructor() ERC20("Mock DAI", "DAI") {
        _mint(msg.sender, 1000000 * 10 ** decimals());

Thanks a lot in advance!!

1 Like