I need to perform some xml parsing using a machine that I may not have permission to install libraries in. So is it possible to include a 开发者_C百科python library like lxml with my source?
Have you tried using virtualenv? That should let you use lxml without "installing" it.
For pure python libraries, you can do that. Unfortunately, lxml depends on a bunch of compiled c code, so it's not going to be generally portable in the way you want.
Using virtualenv is a good alternative, since it helps isolate a project and the installed files. For lxml to work, you'll need the libraries necessary to compile code, which your system may not contain.
Sometimes yes... you can put some libraries source code folder in your project and use it as a module, don't know if it works for lxml but for pure python libraries it works.
Another option is to install it "locally" using this:
python setup.py install --home=<dir>
An option is to add the directory that contains the module you want to sys.path
.
For example:
path = r'C:\extra_libraries\lxml'
import sys
sys.path.append(path)
import lxml
sys.path.pop() # If you want to keep the environment clean
精彩评论