Problem Formulation: Given a PyCharm project. How to install a library in your project within a virtual environment or globally?
Solution that (almost) always works:
- Open
File > Settings > Project
from the PyCharm menu. - Select your current project.
- Click the
Python Interpreter
tab within your project tab. - Click the small
+
symbol to add a new library to the project. - Now type in the library to be installed, for example Pandas, and click
Install Package
. - Wait for the installation to terminate and close all popup windows.
Here’s the installation process as a short animated video:
How to Install a Library on PyCharm?
In some PyCharm versions, the installation steps will be slightly different. If this is you, here are the steps that are likely to work for you to install a library in PyCharm:
- Open PyCharm and select the project where you want to add the library.
- Go to
"File" > "Settings"
(On MacOS, it’s"PyCharm" > "Preferences"
). This will open the Settings/Preferences dialog box. - In the Settings/Preferences dialog box, go to
"Project: <Your_Project_Name>" > "Project Interpreter"
. - Here, you will see a list of packages already installed in your current project’s environment.
- To add a new package, click on the
"+"
button at the bottom of the package list. - In the
"Available Packages"
dialog box that opens, you can search for the library you want to install. - After finding the desired library, select it and click on the
"Install Package"
button at the bottom of the dialog box. - PyCharm will then install the package in your project’s environment.
- Once installation is complete, you should see the new library in the list of packages in the Project Interpreter settings.
Please note that PyCharm will use the interpreter which is selected for the project. So, the installed library will be added to the interpreter used for the project, and it may not be available to other projects or other Python interpreters on your computer.
Also, the package management is done using pip
, so if pip
is not installed or not working in your environment, you may face issues while installing the libraries.
Check out the following Finxter guide on installing pip
:
β How to Install PIP in Python?