Installing and Managing Python Packages
In the previous step, we set up a Python interpreter for our project. But sometimes our project depends on Python packages and getting those setup can be tricky.
Package Tool Window
In 2021, PyCharm added a new Packages tool window to help you see which Python packages are in your interpreter, as well as manage them. You can use this to see what packages PyCharm has installed, for example some will be installed if you select Flask as your project type such as the Jinja2 and Flask packages.

It’s important to mention that these packages belong to the current virtual environment that PyCharm also created for this project.
In this case, a virtual environment in this project directory, based on Python 3.10. You can see this information by clicking on the Status Bar.

Add PyPI Package
You can also browse and install PyPi packages such as requests; a very popular Python package. In the Packages tool window you can type in requests and PyCharm will search the PyPi repository and return the most relevant packages that match your search.
If you click the package name, the PyPi documentation for this package is shown on the right-hand side. Not all minor packages have PyPi documentation so in some cases it will not be available.
To install the package, you can click Install which will use the latest stable version of the package. You don’t need to install it using the command line. You can also select a specific version to install if you need to.

If you now check your list of installed packages, requests is there, ready to be imported and used in our scripts. You might also want to delete a package. In this case, you need to click the three dots and then select Delete package.
PyCharm can manage local or remote environments, pip vs. conda vs. pipenv vs. poetry, and more!
Add Repository Package
We’ve covered how to install packages from PyPi, but you might also want to install packages from a version control system like GitHub or from your local machine. In this case, you can click Add packages in the Package tool window and then you have two options:
- Add packages from version control
- Select the version control system that you’re using and specify a path to the target repository.
- You can provide the local path to your package directory or an archive.
In both cases, you can select the -e checkbox to install the package in editable mode.
Conclusion
You just saw how easy it is to install and manage Python packages in PyCharm. Another quick tip is that sometimes people install Python packages from the local terminal without having the virtual environment activated. In this case, when you import the package using PyCharm, you will see a red squiggly line and an error saying ‘No module named requests’, for example. You can prevent this kind of error by using PyCharm to install and upgrade your packages.
In the next step, we’ll see some basic code assistance tips that will boost your productivity in PyCharm.
Video
You can also check out the video for this step from our Getting Started series on YouTube:
Как установить в pycharm библиотеку PIL

В PyCharm вы можете установить библиотеку, пользуясь встроенным средством:
Там можно настроить путь к вашему Python и установить библиотеку из списка

1) Активируйте виртуальное окружение (из папки vk ):
2) Установите Pillow :
Ошибка в том, что Вы не активировали виртуальное окружение, поэтому установили Pillow в папку C:\Users\User\AppData\Local\Programs\Python\Python37-32\Lib\site-packages .
Cкрипт ищет модуль в папке C:\Users\User\PycharmProjects\vk\venv\Lib\site-packages , следовательно его нужно туда установить, активировав окружение.
PyCharm Project Add External Library (PyMySQL) Path Example
When I use PyCharm to develop a Python example, I need to import a 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. But how to install and import libraries in PyCharm? This article will tell you how to add external libraries to the PyCharm project step by step, it is different from adding external libraries in eclipse PyDev.
Resolving intra-project imports in Python — A simple guide — PyCharm

This article provides a minimal step-by-step guide on how to set up intra-project Python imports correctly in PyCharm.
This article will use the “simple” project structure from the parent article, where source folders and test folders are all at the same level directly under the project root folder.
N.B. This project structure is fine for anyone who has no plans to distribute their code. If, however, you plan to distribute your code to others, e.g. through PyPI, you should consider using a src project structure instead. Follow this link (coming soon) for a step-by-step guide to project file import setup using a src project structure.
Import Statements
The first step we should do is ensure all import statements are written correctly. All imports should be absolute imports starting from under the project root.
Consider project/folder1/file1.py which contains a simple add() function.
We want to use this function in project/folder2/file2.py . Our import is simply from folder1 import file1 — an absolute import that starts from under the project root.
Ensure all imports in your project are set up like this.
Setting up imports for PyCharm Run Configurations
If you only ever run your code through PyCharm Run configurations, no more action is required. Your code should run without a problem. However, if you wish to run your code in a shell, even in the PyCharm integrated terminal, the rest of the article covers this process.
(If you are having import issues and you are running your code through PyCharm, check your Run/Debug configurations are set up correctly. In particular, ensure that Add source roots to PYTHONPATH is selected for your configuration. This option is a default option for every Python configuration, but if you are having issues, check that this option was not accidentally unselected.)
Setting up imports for the Terminal
Running code or tests through the shell require a little bit more work. In order for imports to work correctly, you will need to turn the project into a proper Python package and install it.
You will need to do a number of things:
- Create a venv (if you haven’t already)
- Set up a package for your project
- Install your project
Create a venv
If you already have a venv created and activated, feel free to skip this section.
You will need to create a venv (short for virtual environment) to install your project to. A venv is a lightweight version of Python separated from your system installation of Python, and is typically created for each new Python project. Installing packages to a venv means that packages for each Python project are isolated from each other.
In File — Settings, navigate to Project: <your project name> and then Python Interpreter. Next to the Python Interpreter dropdown field, there should be a little gear icon — click that and then click Add.
In the Add Python Interpreter window, ensure Virtualenv Environment is selected on the left pane. In the main section, ensure New environment is selected. The location should be a venv folder within your project root directory. Ensure the base interpreter is as you expect, and then click OK.
This will create the venv and automatically activate it for you. Click OK on the Settings window to go back to the IDE.
Ensure the project has the venv added to it.
Now, close any existing Terminal tabs within PyCharm and open up a fresh Terminal. You will be able to see if your venv is up and active by the (venv) prefix to the directory in the shell. If so, you are good to go.
(For more information on virtual environments, including how to create them directly from the shell, please visit the following link: https://docs.python.org/3/tutorial/venv.html )
Set up a package for your project
Now, you will need to create a package for your project. This is done by creating a setup.py file using the setuptools package, which should already be available to you in your Python installation.
Ensure your project folder is selected in the Project pane. Then, in the Tools menu, select Create setup.py.
A dialogue box will appear asking for a bunch of details. The defaults should be fine for now; just click OK.
A setup.py file should now be created for you in your project root.
The contents of this file can be left like this for now for our purpose, which is getting imports working locally. If you plan to distribute your code later, you will need to return to this file and change it as necessary.
Installing your project
Now, install your project to your venv. The project will be installed in “editable” mode — this is so that any changes to the installation will automatically update as your project code changes.
Go to the Terminal. Make sure that your venv is active and that the directory is set to the project root. Then, run the following command in the shell:
- Windows: py -m pip install -e .
- macOS/Linux: python3 -m pip install -e .
Once the shell says that the project has been successfully installed, you are good to go.
Further confirmation of the installation of your project will be the appearance of a .egg-info folder in your project folder.
And we’re done!
It was a roundabout trip, but we got there! If you now run your code or your tests from the shell (using the py command on Windows or the python3 command on macOS/Linux) everything should just work.