Naive Confusion about Package Installation

Hello!

I am using PyCharm 2023.3.5 (Community Edition). I have got myself into a mess owing to lack of knowledge of installation options.

I need to install a package, preferably using the PyCharm IDE. Unfortunately, here is a summary of my self-inflicted challenge:

Package: paho-mqtt-client
Interpreter path: /usr/bin/python3.11
Python version: Python 3.11.6
$ python3 -m pip install paho-mqtt
Requirement already satisfied: paho-mqtt in ./lib/python3.11/site-packages (1.6.1)

Navigating from Python Packages → entering the name of the package → selecting the package → selecting Install → selecting Install package on the new pane leads to the following message:

error: externally-managed-environment

I do not wish to install this package system-wide using the traditional sudo apt install method. My lack of elementary knowledge should be apparent. I need HELP, please!

What are the steps needed for corrective action on my part to successfully install a package using Pycharm IDE? Thanks.

Regards.

0
3 comments

Sounds like you need your project to use a “virtual environment”.  From Pycharm do this:

Pycharm →Settings → Project→Python Interpreter

From this dialog click

Add Interpreter→Add Local Interpreter

From this dialog make sure “Virtualenv Environment” is selected in the left tree and the toggle Environment “New” is selected

Make sure Base Interpreter is the path you showed above

Click Ok (twice)

You now have a virtual environment in your project directory in the directory .venv;  You should be able to install your package in that environment since it is now your default

1

Hello Humberto,

Sorry, I forgot to clarify, I am using a virtual environment - venv. I dutifully do:

source ./bin/activate

from the working directory before launching PyCharm IDE. Anyway, I will try out your suggestion shortly. Thanks.

Regards.

0

Thanks, Humberto, once again!

Your suggestion worked fine to get the mqtt package working but I lost my cv2 (OpenCV) package. I'll figure that out based on your guidelines. Many, many thanks again for taking the time to help me out.

Regards.

0

Please sign in to leave a comment.