开发者

Customising Install location for Django (or any Python module)

开发者 https://www.devze.com 2022-12-09 15:08 出处:网络
I\'d like to to install Django into a custom location, I\'ve read the distutils documentation and it suggests that I should be able to do something like the following to install under my home director

I'd like to to install Django into a custom location, I've read the distutils documentation and it suggests that I should be able to do something like the following to install under my home directory (when run from an unpacked django tarball).

> python setup.py install --home=~/code/packages/install --install-purelib=modules --install-platlib=modules --install-scripts=scripts --install-data=data 

However, every time I run this, it doesn't seem to concatenate the home path with the separate element paths, and so I simply end up with

modules/
scripts/
data/ 

In the unpacked tar ball directory. I.e. it seems to be treating modules, scripts etc as simply relative paths to local directory and not relative to the --home specified.

I've tried setting the root with --prefix, and using a setup.cfg and nothing seems to work. --prefix and and --home on their own with no other overrides work, but when used together with --install-x开发者_如何学Goxx overrides it doesn't.

I'm either probably doing something stupid, or the documentation is wrong, or their is a bug. Any help much obliged.


I would strongly suggest that you look at Virtualenv and Pip for creating basically silos of python packages.

The Pinax project uses this exclusively now for bundling requirements together for other people to use, and it's becoming more and more of a defacto standard in the reusable apps space.


Ok, so I've been looking at the distutils source code to see what is going on - distutils.command.install does all of the pathname manipulation.

It turns out that the documentation is actually incorrect. Whenever an --install-xxxx style option is provided it completely overrides any value that might be derived from --home or --prefix - the code not does do any straightforward concatenation of paths.

However, what it does do is variable substitution of a set of special variables. The one of interest to me specifically is $base. Using it on the command line you can define the overrides, and distutils will replace all occurrences with what was specified for --home etc. But note you must quote your filenames so BASH does not try expand it as a environment variable.

So the command line that I had initially, becomes:

python setup.py install --home=/home/andre/code/packages/install --install-purelib='$base/modules' \
  --install-platlib='$base/modules' --install-scripts='$base/scripts' --install-data='$base/data'

Hope someone other than me finds that useful!


As a quick check, I'd suggest replacing

~/code/packages/install

with

/full_path_to_your_user/code/packages/install


If you just want it in your home directory, there's no need to install it at all. Just make sure that the container directory is on your pythonpath somewhere, and move the scripts in django/bin into somewhere on your main PATH (or add that dir to your path).

0

精彩评论

暂无评论...
验证码 换一张
取 消