Windows10下Conda环境运行rdkit时DLL加载失败问题求助
I have installed Conda on Windows 10, and followed the official docs to install RDKit. When I run conda list, RDKit shows up in the output:
rdkit 2018.03.1.1 py35he980bc4_1 rdkit
But after activating the RDKit environment (activate my-rdkit-env) and launching Python, trying to import rdkit throws this error:
>>> import rdkit Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Bakary\AppData\Local\conda\conda\envs\my-rdkit-env\lib\site-packages\rdkit\__init__.py", line 2, in <module> from .rdBase import rdkitVersion as __version__ ImportError: DLL load failed: The specified module could not be found.
I need to fix this to use RDKit in PyCharm.
Solutions to Fix the DLL Load Error
This is a super common issue with RDKit on Windows, usually tied to path misconfiguration or missing system dependencies. Let's walk through the fixes step by step:
1. Manually Add RDKit's Bin Directory to Your PATH
Conda is supposed to automatically add the RDKit library's bin folder to your PATH when you activate the environment, but sometimes this doesn't kick in properly. Here's how to fix it:
- Locate the
Library\binpath of your RDKit environment: for your setup, it'sC:\Users\Bakary\AppData\Local\conda\conda\envs\my-rdkit-env\Library\bin - First activate your environment:
activate my-rdkit-env - Run this command to prepend the bin path to your system PATH:
set PATH=C:\Users\Bakary\AppData\Local\conda\conda\envs\my-rdkit-env\Library\bin;%PATH% - Launch Python again and try
import rdkit—this should resolve the missing DLL issue if it was just a path problem.
2. Recreate the RDKit Environment to Fix Version Conflicts
Sometimes leftover packages or subtle version mismatches can break DLL loading. Try spinning up a fresh environment with compatible versions:
conda create -n new-rdkit-env python=3.5 rdkit conda activate new-rdkit-env python -c "import rdkit; print(rdkit.__version__)"
If this works, you can switch to using this new environment in PyCharm instead of your old one.
3. Configure PyCharm to Use the Correct RDKit Environment
Make sure PyCharm is pointing at the right Python interpreter from your RDKit environment:
- Open PyCharm and navigate to File > Settings > Project: [Your Project Name] > Python Interpreter
- Click the gear icon in the top-right corner and select Add
- Choose Conda Environment > Existing environment, then browse to
C:\Users\Bakary\AppData\Local\conda\conda\envs\my-rdkit-env\python.exe - Click OK to save the config, then restart PyCharm if needed. Test the import in a PyCharm terminal or run a simple test script to confirm.
4. Install the Required Visual C++ Redistributable
RDKit on Windows relies on the Visual C++ 2015 Redistributable Package (v14 runtime). If you don't have this installed:
- Grab the appropriate version (x86 or x64) from Microsoft's official site
- Install it, restart your computer, then try importing RDKit again.
内容的提问来源于stack exchange,提问作者BND

