How to import a module installed with "pip3 install <packagename> --prefix=/my/own/path"?

I am using python 3.7. I know there are multiple ways to install a python module. My question is related to the following scenario

pip3 install exchangelib --prefix /my/own/path1

the installation was good. But not sure how to make the “import exchangelib” work. I tried with sys.path.append and set the PYTHONPATH environment variable. These two methods work for the module installed with “pip install exchangelib --target /my/own/path2”

Do we know what the difference among those two installations?


1 Like

--prefix is for specifying the top-level directory, where “lib”, “bin”, “include”, “share” etc are. You’ll notice this structure in (on Ubuntu) “/usr/local”, “~/.local/”, and in virtual environment directories. Packages will be installed into “lib/PythonX.Y/site-packages/” under it.

--target is the option you want for choosing the precise installation directory, then using PYTHONPATH to point Python to it, as you said