I installed the pynput Python package with pip. I got this error in PyCharm when trying to import pynput with import pynput.
C:\Users\User\PycharmProjects\keyloger.py\Scripts\python.exe "C:/Users/User/Desktop/hello world.py" Traceback (most recent call last): File "C:/Users/User/Desktop/hello world.py", line 1, in <module> import pynput ModuleNotFoundError: No module named 'pynput' Process finished with exit code 1 Even though pynput is installed, import pynput in PyCharm can't find it.
1 Answer
By default, PyCharm uses pip to manage project packages. To manage Python packages for the project interpreter, select the Project Interpreter page in the project Settings/Preferences or select Interpreter Settings in the Python Interpreter widget.
Select File -> Settings -> Project: project_name -> Project Interpreter. Click the + button which is marked by the mouse cursor in the screenshot to install Python packages in the selected project.
Search for any Python package. Select it and click the Install Package button in the lower left corner of the Available Packages window to install it. PyCharm will automatically choose the package version for you or you can check the checkbox to the left of Specify version and select the package version from the Specify version dropdown menu.
As you can see in the above screenshot pynput is not in the list of available packages, so you need to follow the instructions after the 2nd screenshot to use the pynput package that you already installed with pip instead of reinstalling pynput in PyCharm.
Whenever you install a Python package specifically for a project, PyCharm adds the packages that were installed to the project's venv directory where PyCharm will find them automatically.
PyCharm does not automatically find your globally installed Python packages unless the project has been configured to find them. To do this select the Inherit global-site packages option when you create a new project.
Select File -> New Project to create a new project. Click the triangle marked by the mouse cursor in the below screenshot to show the new project's options.
Then check the Inherit global-site packages checkbox and click the Create button in the lower right corner of the Create Project window.
0


