2014-07-14 82 views
8

我有一個Python包,我需要安裝在/usr/lib/python2.7/dist-packages或任何其他特定的目錄。如何使用setuptools安裝在自定義目錄中?

每當我運行setup.py腳本它提供了以下的輸出:

[email protected]:~/som_dir/plugins/abc$python setup.py install 
running install 
running bdist_egg 
running egg_info 
writing abcNewPlugin.egg-info/PKG-INFO 
writing top-level names to abcNewPlugin.egg-info/top_level.txt 
writing dependency_links to abcNewPlugin.egg-info/dependency_links.txt 
writing entry points to abcNewPlugin.egg-info/entry_points.txt 
reading manifest file 'abcNewPlugin.egg-info/SOURCES.txt' 
writing manifest file 'abcNewPlugin.egg-info/SOURCES.txt' 
installing library code to build/bdist.linux-x86_64/egg 
running install_lib 
warning: install_lib: 'build/lib.linux-x86_64-2.7' does not exist -- no Python modules to install 

creating build/bdist.linux-x86_64/egg 
creating build/bdist.linux-x86_64/egg/EGG-INFO 
installing scripts to build/bdist.linux-x86_64/egg/EGG-INFO/scripts 
running install_scripts 
running build_scripts 
creating build/bdist.linux-x86_64/egg/EGG-INFO/scripts 
copying build/scripts-2.7/abc_plugin.py -> build/bdist.linux-x86_64/egg/EGG-INFO/scripts 
changing mode of build/bdist.linux-x86_64/egg/EGG-INFO/scripts/abc_plugin.py to 775 
copying abcNewPlugin.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
zip_safe flag not set; analyzing archive contents... 
creating 'dist/abcNewPlugin-0.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it 
removing 'build/bdist.linux-x86_64/egg' (and everything under it) 
Processing abcNewPlugin-0.0-py2.7.egg 
Removing /usr/local/lib/python2.7/dist-packages/abcNewPlugin-0.0-py2.7.egg 
Copying abcNewPlugin-0.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages 
abcNewPlugin 0.0 is already the active version in easy-install.pth 
Installing abc_plugin.py script to /usr/local/bin 

Installed /usr/local/lib/python2.7/dist-packages/abcNewPlugin-0.0-py2.7.egg 
Processing dependencies for abcNewPlugin==0.0 
Finished processing dependencies for abcNewPlugin==0.0 

有什麼辦法來指定setuptools的安裝包的目錄? 我試圖--install-dir選項,但它給出了一個錯誤:

$sudo python setup.py install --install-dir=/usr/lib/python2.7/dist-packages 
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] 
    or: setup.py --help [cmd1 cmd2 ...] 
    or: setup.py --help-commands 
    or: setup.py cmd --help 

error: option --install-dir not recognized 

我不能使用--prefix選項也。

回答

9

由於python setup.py install命令只是一個快捷方式到easy_install,嘗試直接運行它,它具有--install-dir選項:

easy_install . --install-dir /usr/lib/python2.7/dist-packages 

你可以得到其他可用選項與python setup.py install -h,你需要更多的一些情況,但這些都很神祕。

+1

在python3(至少)的標誌是現在'--prefix',而不是'--install-dir' 您也可以針對**用戶網站包**('/home/user/.local/lib/python3.5/site-packages')通過使用'--user' – Nande

1

--install-lib設置安裝目錄模塊

python setup.py install --install-lib /src/lib/ 
+0

通常最好是解釋一個解決方案,而不是隻發佈一些匿名行碼。你可以閱讀[我如何寫一個好的答案](https://stackoverflow.com/help/how-to-answer),還有[完全解釋基於代碼的答案](https://meta.stackexchange.com /問題/ 114762 /解釋-entirely-%E2%80%8C%E2%80%8Bcode基於-答案)。也許你可以指定你的解決方案爲什麼工作... –

相關問題