Pycharm Import External Library

How can I import external libraries in PyCharm?

Using a new virtual environment

I recommend that you create a virtual environment for your project. That will isolate your project's dependencies from your system-wide Python installation. PyCharm should propmt you to do so when you create a new project. Otherwise:

  1. Go to Settings > Project > Project Interpreter, click the cog button and select Add...
    Add interpreter
  2. Select New environment. The default settings should be fine. Click OK.
  3. Make a list of the packages you want to install in a file requirements.txt in your project's root directory, with one on each line, and then run pip install -r requirements.txt from the PyCharm terminal


Existing interpreter

If you prefer to use an existing interpreter, though, you can also use it from PyCharm without recreating it. Any packages you have installed with that interpreter will ve available without reinstalling.

First, make sure that your Python interpreter in which you installed all your packages is available in PyCharm. Follow step 1. above, but replace step 2. with


  1. Select Existing environment. Click the three dots to locate your python interpreter in your file system. Click OK.

Then, once the interpreter is added, make sure to select it in Settings > Project > Project Interpreter, or use the interpreter menu in the bottom-right corner:

PyCharm interpreter quick menu

PyCharm include and modify External library in project

Well, you can add other directories as content roots:

Sample Image

Then simply mark the directory as a source root:

Sample Image

This should allow you to refactor, rename and do all the things you've wanted to do.

PyCharm and external libraries

I suggest to use Python virtual environment. It is really easy with PyCharm.

PyCharm > Preferences... > Project Interpreter > Python Interpreters

Click "Create Virtual Environment" and pick your base interpreter.

Sample Image

Click "Install" and install any packages you need. You can also add other repositories if the default ones do not contain required libraries. Another benefit is that you can see which libraries have newer version and can be updated.

Sample Image

Indexing of external library fails in PyCharm 4.5

Checked w/ JetBrains support, they confirmed that the only ways to add external libraries to a PyCharm project are:

  • Add the library as a Content Root
  • OR
  • Open it as separate project in the same window and attach it to your current project

Not the cleanest approaches, as they both basically mean adding the other library's actual code to your project. But they are the only ones at this point.



Related Topics



Leave a reply



Submit