'I'm confused by pip installations

I have recently begun having troubles using pip to install python packages. I have always used pip but never really understood how it actually works, my experience with it is basically limited to "pip install pkg".

Recently when trying to install openCV on my machine, I followed a few guides that involved changing paths etc. Since making these changes I have been having trouble using pip to install packages correctly.

Now when I run "pip3 install pkg", the install runs fine without any errors. When I try to import the module in python however, python cannot find the package. If I run "pip3 list" in the terminal I get a list of modules that is different to running help('modules') within python.

I think pip is installing the packages to a different location than my version of python is referencing when importing modules?

Is there a way I can change where pip installs to? What did it mean to change paths and how can I avoid this in the future?

Thanks in advance.

EDIT: I should mention that running "python3 -m pip install pkg" installs the packages correctly.



Solution 1:[1]

Because you have 2 versions of python installed, the best solution is to install and use virtualenv

A Virtual Environment is a tool to keep all dependencies required by different projects and python versions in separate places. It solves the problem you mentioned and keeps your site-packages directory manageable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Glorfindel