giordano
giordano

Reputation: 3152

Python - How to define a another library source

I'm new in Python and I have knowledge of R. Due to admin-restriction I can't install packages in folder
C:\Program Files (x86)\Python37-32\Lib

Now, I'm wondering if I can install the package in a folder C:\libPython

and considering this folder when I import the library. So, there are two tasks to carry out:

  1. Install a package into C:\libPython
  2. To "inform" python that there is apart from the standard library source another source C:\libPython.

In R both steps are done by defining the new path:

myLib <- "C:/libR"
.libPaths(myRLib)
install.packages("somewhat", lib=myRLib)
library(somewhat)

I'm using Windows 7 and 10.

Upvotes: 2

Views: 59

Answers (1)

AutoTester213
AutoTester213

Reputation: 2862

To install the package you can use --target command

pip install --target=C:\Lib package_name

--target dir

Install packages into dir. By default this will not replace existing files/folders in dir. Use –upgrade to replace existing packages in dir with new versions.

And to use the package you can add C:\Lib to the PYTHONPATH env variable, this way you tell python that there are packages in a different folder than default

Upvotes: 2

Related Questions