python安装笔记_python安装笔记

ref: python doc - Installing Python Modules (Legacy version)

python setup.py build

python setup.py install

1. build

python setup.py build

the build command is responsible for putting the files to install into a build directory.

change the build dir:

python setup.py build --build-base=/path/to/pybuild/foo-1.0

2. install

python setup.py install

the install command is relatively simple: copy everything under build/lib (or build/lib.plat ) to your chosen installation directory.

2.1 alternate installation

The basic idea is that you supply a base directory for the installation, and the install command picks a set of directories (called an installation scheme) under this base directory in which to install files.

--user

--home

--prefix

--exec-prefix

--install-base

--install-platbase

2.1.1 alternate installation - the user scheme

When don’t have write permission to the global site-packages directory or don’t want to install into it:

python setup.py install --user

Type of file

Installation directory

modules

userbase/lib/pythonX.Y/site-packages

scripts

userbase/bin

data

userbase

C headers

userbase/include/pythonX.Y/distname

2.1.2 Alternate installation: the home scheme

when you build and maintain a personal stash of Python modules. just like Unix's "home" dir.

e.g. python setup.py install --home=~

Type of file

Installation directory

modules

home/lib/python

scripts

home/bin

data

home

C headers

home/include/python/distname

2.1.3 Alternate installation: Unix (the prefix scheme)

when you wish to use one Python installation to perform the build/install (i.e., to run the setup script), but install modules into the third-party module directory of a different Python installation (or something that looks like a different Python installation).

e.g. /usr/local/bin/python setup.py install --prefix=/mnt/@server/export

Type of file

Installation directory

Python modules

prefix/lib/pythonX.Y/site-packages

extension modules

exec-prefix/lib/pythonX.Y/site-packages

scripts

prefix/bin

data

prefix

C headers

prefix/include/pythonX.Y/distname

every time you run python setup.py install without any other options, you’re using --prefix and --exec-prefix.

2.2 Custom installation

Type of file

Override option

Python modules

--install-purelib

extension modules

--install-platlib

all modules

--install-lib

scripts

--install-scripts

data

--install-data

C headers

--install-headers

python setup.py install --home=~/python \

--install-purelib=lib \

--install-platlib='lib.$PLAT' \

--install-scripts=scripts

--install-data=data

or use Distutils config file (see section Distutils Configuration Files):

[install]

install-base=$HOME/python

install-purelib=lib

install-platlib=lib.$PLAT

install-scripts=scripts

install-data=data

2.2.1 Modifying Python’s Search Path

When the Python interpreter executes an import

statement, it searches for both Python code and extension modules along a search path. A default value for the path is configured into the Python binary when the interpreter is built. You can determine the path by importing the sys

module and printing the value of sys.path.

The most convenient way is to add a path configuration file to a directory that’s already on Python’s path, usually to the .../site-packages/ directory. Path configuration files have an extension of .pth, and each line must contain a single path that will be appended to sys.path. (Because the new paths are appended to sys.path, modules in the added directories will not override standard modules. This means you can’t use this mechanism for installing fixed versions of standard modules.)

import sys

sys.path.append('/www/python/')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值