A problem I frequently run into when using Python, R, Matlab etc. is installing packages or libraries when I 开发者_Go百科don't have admin privileges on the server I'm using. I was wondering if there is a way to get around this?
I was thinking of "installing" the libraries somewhere in my own account, and adding that directory to my path, rather than somewhere like /usr/bin, /usr/lib etc. Does anyone have any tips / pointers on this? This must be a frequent problem for college / graduate students.
Thanks!
Take a look at virtualenv, that should do the trick for you.
For R you can do install.packages("foo",lib="~/R/") - create the directory ~/R/ first - and then the packages will install there. Then do library(foo,lib="~/R/") to load it.
You can use the .libPaths function in your R startup files to add this automatically. Most of the Ubuntu boxes I've used are set up something like this by default. If a plain user tries to install a package it goes into their ~/R/ library, if root tries to do it, it goes into a site library for everyone.
Since generally there's no point backing up these installed packages, I tend to put my ~/R/ library on a non-backed up part of my filesystem.
[Note the correct use of 'library' here - in R-speak a library is a place where packages are installed]
In Matlab you typically can just download the m files anywhere you like, and then add their location to the path. Not sure but I would suspect that getting a complete toolbox may require admin rights but for anything less you should be fine.
To conveniently add the location to your path automatically when you run matlab you can edit startup.m
In python you can do python setup.py install --user
or pip install --user foo
. This will install it in a user-specific directory appropriate for your platform.
精彩评论