简体   繁体   English

'dist-packages'与'site-packages'中的Python模块

[英]Python module in 'dist-packages' vs. 'site-packages'

I am building a deb package from source. 我正在从源代码构建deb包。 The source used to install the modules in 'site-packages' in RHEL. 用于在RHEL中的“site-packages”中安装模块的源。

On Ubuntu, 'site-packages' doesn't work for me. 在Ubuntu上,'site-packages'对我不起作用。 Searching over the net, it says that python Ubuntu would require it in 'dist-packages' 通过网络搜索,它说python Ubuntu会在'dist-packages'中要求它

But there are also references that python built from source would look in 'site-packages' 但也有一些参考资料,从源代码构建的python会在'site-packages'中查找

Now I am confused, where should my deb packages install the modules so that it works irrespective of python built from source or installed from Ubuntu repo 现在我很困惑,我的deb软件包应该在哪里安装模块,以便无论从源代码构建的python还是从Ubuntu repo安装的python都可以运行

dist-packages is a Debian convention that is present in distros based on Debian. dist-packages是一个基于Debian的发行版中的Debian约定。 When we install a package using the package manager like apt-get these packages are installed to dist-packages. 当我们使用像apt-get这样的包管理器安装包时,这些包被安装到dist-packages。 Likewise, if you install using pip and pip is installed via package manager then these packages will be installed in dist-packages. 同样,如果您使用pip安装并且pip是通过软件包管理器安装的,那么这些软件包将安装在dist-packages中。

If you build python from source then pip comes with it, now if you install a package using this pip it'll be installed into site-packages. 如果你从源代码构建python然后pip自带它,现在如果你使用这个pip安装一个包,它将被安装到site-packages中。

So It depends on which python binary you are using if you are using the binary that comes from package manager it will search in dist-packages and if you are using a binary from manual install it'll search in site-packages. 所以这取决于您使用的是哪个python二进制文件,如果您使用来自包管理器的二进制文件,它将在dist-packages中搜索,如果您使用手动安装的二进制文件,它将在site-packages中搜索。

从我从IRC学到的是我应该只在'dist-packages'中安装模块,假设管理员只安装了Ubuntu repo提供的python。

There is a "purelib" and a "platlib" directory. 有一个“purelib”和一个“platlib”目录。 You can find out what they are by running: 你可以通过运行找出它们是什么:

$ python -c "import sysconfig; print sysconfig.get_paths()['purelib']"

$ python -c "import sysconfig; print sysconfig.get_paths()['platlib']"

Note however that by doing this you already select a certain python installation. 但请注意,通过执行此操作,您已经选择了某个python安装。 As said above, the exact path depends on the installation. 如上所述,确切的路径取决于安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM