首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    Python模块默认路径

    环境介绍: OS:RHEL 5.5 Python版本:2.7.6 Python之所以强大,最重要原因是Python有很丰富的库(模块)可以比较方便地处理各种各样的问题。 那么问题来了,Python的第三方modules一般安装在哪? Unix(Linux): prefix/lib/pythonX.Y/site-packages 默认路径:/usr/local/lib/pythonX.Y/site-packages Windows: prefix\Lib\site-packages 默认路径:C:\PythonXY\Lib\site-packages 另外,在Unix-like系统上,Python自身build-in的模块一般位于:/usr/lib/pythonX.Y/site-packages 从源代码安装模块的命令一般为:setup.py install 当然,可以根据需要改变默认的第三方模块安装路径,在命令中可以加上参数:–user, or –home, or –prefix and –exec-prefix, or –install-base and –install-platbase 等来指定安装路径。 需要注意的是:模块的安装路径一定要在 sys.path 这个List中,才能在脚本中可以正常地 import 进来。 关于模块的安装, Python官方参考文档是: https://docs.python.org/2/using/windows.html#finding-the-python-executable

    02

    Python包管理整理:setuptoo

    setuptool管理python相关的包 一、介绍 setuptool管理python相关的包的工具。这些包是zip格式发布,但是后缀一般都是.egg setuptool能解决python包的依赖关系 setuptool安装的包默认安装到/usr/local/lib/pythonX.X/site-packages/目录下 下载包默认到http://pypi.python.org/pypi下载 pypi为Python PackageIndex 二、安装setuptool工具 1、rhel/centos #yum -y install python-setuptools 2、freebsd #cd /usr/ports/devel/py-setuptools && make install clean 3、debian/ubuntu #sudo apt-get install python-setuptools 以上使用系统包管理系统安装后需要更新一下: # easy_install -U setuptools 4、通用方式 Download ez_setup.py , and then run: ez_setup.py -Zf http://peak.telecommunity.com/snapshots/ RuleDispatch #fetch http://peak.telecommunity.com/dist/ez_setup.py #python2.7 ez_setup.py python2.7指定版本号,以表示setuptool使用的python版本。未指定版本则使用默认,也表示默认安装的版本是最新版本。 这一约定方便,旧版本也可以继续使用 三、通过easy_install安装python包 (一)普通安装 #easy_install Babel (二)安装本地或网络文件系统中安装egg文件 #easy_install /net/src/eggs/py2.5.egg (三)指定包的下载路径安装 #easy_install http://trac-hacks.org/svn/iniadminplugin/0.11/ #easy_install http://trac-hacks.org/svn/accountmanagerplugin/trunk (四)从URL源码包安装 #easy_install  http://pypi.python.org/simple/asp/asp-0.1.2.4.tar.gz 条件asp-0.1.2.4.tar.gz包中的根目录中必须包括setup.py文件 (五)web上面搜索包,并自动安装 # easy_install -f http://pypi.python.org/simple/ asp (六)指定包的版本 # easy_install asp==0.1.2.1 如果指定的版本高于现有已安装的保本就是升级了 (七)升级包 升级到最新版本(不指定版本就会升级到最新版本 # easy_install -U asp 升级到指定版本 # easy_install -U asp==0.1.2.2 四、认证和配置文件 1、有些需要认证的python站点 easy_install -f http://uid@password@pypi.python.org/simple/packages 2、使用配置文件定义下载的站点和安装的目录 配置文件位置 当前目录/setup.cfg 或当前目录/.pydistutils.cfg 配置文件内容 find-links=http://pypi.python.org/simple/ #特定搜索包的URL allow=*.python.org #搜索的域名 install_dir=/src/lib/python    #这个目录需要在PYTHONPATH中 (sys.path) 更多帮助请看easy_install --help

    01
    领券