When i use PyCharm to develop Python example, i need to add a third-party library ( PyMySQL : A MySQL database Python driver library. ) into the Python project path, so that PyCharm can find the library files when coding and executing source code. This article will tell you how to add external libraries into PyCharm project, it is different from adding external library in eclipse pydev.
1. Add External Libraries In PyCharm Project On MacOS.
This example use PyCharm MacOS version, PyCharm Windows or Linux version is similar.
- Open PyCharm, click PyCharm —> Preferences menu item.
- Then click Project —> Project Interpreter menu item in left panel.
- Click the
+button in right panel bottom left corner to popup the install third party library window.
- Input the library name in the search text box, select the library and click Install Package button to install it.
- When the installation process complete successfully, you can see the third-party library in the project interpreter package list. Click OK button to save the changes.
- If you want to add external libraries for new project in PyCharm, you can click File —> Preferences for New Projects menu item to open a popup window, then click Project Interpreter menu item in left panel, then install python library in right panel like above.
2. Installed Library Saved Location.
After install the third party Python library, you may want to know where the library is installed. In the PyCharm left project panel, select Project view and expand the External Libraries item, then you will find the installed pymysql library in the Python 3.6 —> site-packages folder. Now you can import and use pymysql library in your Python code edited with PyCharm.
3. Install External Library For PyCharm Project On Linux Ubuntu.
- Click PyCharm File —> Settings menu item in top menu bar to open project Settings window.
- Then click Project : <project name> —> Project Interpreter menu item in left panel to list current project interpreter and the installed external libraries.
- Click the
+icon in right panel to open new external library installation window. Search and select related library package. Please note, you should check the Install to user’s site packages directory(/home/zhaosong/.local) checkbox, otherwise you can not find the library package in Project panel —> External Libraries.
- Now you can use the external library package in your Django code and find it in Project panel —> External Libraries —> Python 3.6 —> site-packages.