---
title: "How to add a DLL permanently to python"  
description: "How to add a DLL permanently to python"  
author: "Revati S Misra"  
published: 2023-07-24  
updated: 2023-07-25  
canonical: https://www.mindstick.com/forum/159253/how-to-add-a-dll-permanently-to-python  
category: "python"  
tags: ["dll", "python"]  
reading_time: 2 minutes  

---

# How to add a DLL permanently to python

How to [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) a [DLL](https://www.mindstick.com/forum/34704/dll-dynamic-link-library-in-c-sharp) permanently to [python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)

## Replies

### Reply by Aryan Kumar

There are two ways to add a DLL permanently to Python:

1. Copy the DLL to the same directory as the Python script that needs to use it.
2. Add the directory where the DLL is located to the Python search path.

To copy the DLL to the same directory as the Python script, you can use the following steps:

1. Find the location of the DLL.
2. Copy the DLL to the same directory as the Python script.

To add the directory where the DLL is located to the Python search path, you can use the following steps:

1. Import the `os` module.
2. Use the `os.add_dll_directory()` function to add the directory to the Python search path.

Here is an example of how to add a DLL permanently to Python:

Python

```plaintext
import os

# Find the location of the DLL.
dll_path = "C:\\path\\to\\dll.dll"

# Copy the DLL to the same directory as the Python script.
os.copy(dll_path, ".")

# Add the directory where the DLL is located to the Python search path.
os.add_dll_directory(".")

# Import the DLL.
import my_dll

# Use the DLL.
my_dll.function()
```

In this example, the DLL is copied to the current directory, and the current directory is added to the Python search path. The `my_dll` module is then imported, and the `function()` function is called.


---

Original Source: https://www.mindstick.com/forum/159253/how-to-add-a-dll-permanently-to-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
